Class JsonSerializing.SerializerBuilder<E,T extends JsonSerializableType<E>>

java.lang.Object
net.minecraft.util.JsonSerializing.SerializerBuilder<E,T>
Enclosing class:
JsonSerializing

public static class JsonSerializing.SerializerBuilder<E,T extends JsonSerializableType<E>> extends Object
A builder for serializing types to JSON that can either obtain a type from a registry to handle JSON conversion or handle with a custom logic bound to a type.

When the root element read is an object, the built serializer obtains the type from registry to handle reading; otherwise, it falls back to custom logic.

Mappings:
Namespace Name
official drd$a
intermediary net/minecraft/class_5330$class_5331
named net/minecraft/util/JsonSerializing$SerializerBuilder
  • Field Details

    • registry

      private final Registry<T extends JsonSerializableType<E>> registry
      Mappings:
      Namespace Name Mixin selector
      official a Ldrd$a;a:Lhm;
      intermediary field_25192 Lnet/minecraft/class_5330$class_5331;field_25192:Lnet/minecraft/class_2378;
      named registry Lnet/minecraft/util/JsonSerializing$SerializerBuilder;registry:Lnet/minecraft/util/registry/Registry;
    • rootFieldName

      private final String rootFieldName
      Mappings:
      Namespace Name Mixin selector
      official b Ldrd$a;b:Ljava/lang/String;
      intermediary field_25193 Lnet/minecraft/class_5330$class_5331;field_25193:Ljava/lang/String;
      named rootFieldName Lnet/minecraft/util/JsonSerializing$SerializerBuilder;rootFieldName:Ljava/lang/String;
    • idFieldName

      private final String idFieldName
      Mappings:
      Namespace Name Mixin selector
      official c Ldrd$a;c:Ljava/lang/String;
      intermediary field_25194 Lnet/minecraft/class_5330$class_5331;field_25194:Ljava/lang/String;
      named idFieldName Lnet/minecraft/util/JsonSerializing$SerializerBuilder;idFieldName:Ljava/lang/String;
    • typeGetter

      private final Function<E,T extends JsonSerializableType<E>> typeGetter
      Mappings:
      Namespace Name Mixin selector
      official d Ldrd$a;d:Ljava/util/function/Function;
      intermediary field_25195 Lnet/minecraft/class_5330$class_5331;field_25195:Ljava/util/function/Function;
      named typeGetter Lnet/minecraft/util/JsonSerializing$SerializerBuilder;typeGetter:Ljava/util/function/Function;
    • elementSerializer

      @Nullable private @Nullable com.mojang.datafixers.util.Pair<T extends JsonSerializableType<E>,JsonSerializing.ElementSerializer<? extends E>> elementSerializer
      Mappings:
      Namespace Name Mixin selector
      official e Ldrd$a;e:Lcom/mojang/datafixers/util/Pair;
      intermediary field_25196 Lnet/minecraft/class_5330$class_5331;field_25196:Lcom/mojang/datafixers/util/Pair;
      named elementSerializer Lnet/minecraft/util/JsonSerializing$SerializerBuilder;elementSerializer:Lcom/mojang/datafixers/util/Pair;
    • defaultType

      @Nullable private T extends JsonSerializableType<E> defaultType
      Mappings:
      Namespace Name Mixin selector
      official f Ldrd$a;f:Ldrn;
      intermediary field_28444 Lnet/minecraft/class_5330$class_5331;field_28444:Lnet/minecraft/class_5336;
      named defaultType Lnet/minecraft/util/JsonSerializing$SerializerBuilder;defaultType:Lnet/minecraft/util/JsonSerializableType;
  • Constructor Details

    • SerializerBuilder

      SerializerBuilder(Registry<T> registry, String rootFieldName, String idFieldName, Function<E,T> typeIdentification)
      Mappings:
      Namespace Name Mixin selector
      official <init> Ldrd$a;<init>(Lhm;Ljava/lang/String;Ljava/lang/String;Ljava/util/function/Function;)V
      intermediary <init> Lnet/minecraft/class_5330$class_5331;<init>(Lnet/minecraft/class_2378;Ljava/lang/String;Ljava/lang/String;Ljava/util/function/Function;)V
      named <init> Lnet/minecraft/util/JsonSerializing$SerializerBuilder;<init>(Lnet/minecraft/util/registry/Registry;Ljava/lang/String;Ljava/lang/String;Ljava/util/function/Function;)V
  • Method Details

    • elementSerializer

      public JsonSerializing.SerializerBuilder<E,T> elementSerializer(T type, JsonSerializing.ElementSerializer<? extends E> serializer)
      Sets the element serializer and its target type. It can serialize and deserialize instances of one type to non-JsonObject elements.
      Parameters:
      type - the target type of the element serializer
      serializer - the element serializer
      API Note:
      There can only be one element serializer for this builder and the built serializer. Calling this method replaces any previous serializer.
      Mappings:
      Namespace Name Mixin selector
      official a Ldrd$a;a(Ldrn;Ldrd$b;)Ldrd$a;
      intermediary method_32385 Lnet/minecraft/class_5330$class_5331;method_32385(Lnet/minecraft/class_5336;Lnet/minecraft/class_5330$class_5332;)Lnet/minecraft/class_5330$class_5331;
      named elementSerializer Lnet/minecraft/util/JsonSerializing$SerializerBuilder;elementSerializer(Lnet/minecraft/util/JsonSerializableType;Lnet/minecraft/util/JsonSerializing$ElementSerializer;)Lnet/minecraft/util/JsonSerializing$SerializerBuilder;
    • defaultType

      public JsonSerializing.SerializerBuilder<E,T> defaultType(T defaultType)
      Sets the default type that is used when there's no ID field.
      Parameters:
      defaultType - the default type
      Returns:
      this instance
      Mappings:
      Namespace Name Mixin selector
      official a Ldrd$a;a(Ldrn;)Ldrd$a;
      intermediary method_33409 Lnet/minecraft/class_5330$class_5331;method_33409(Lnet/minecraft/class_5336;)Lnet/minecraft/class_5330$class_5331;
      named defaultType Lnet/minecraft/util/JsonSerializing$SerializerBuilder;defaultType(Lnet/minecraft/util/JsonSerializableType;)Lnet/minecraft/util/JsonSerializing$SerializerBuilder;
    • build

      public Object build()
      Mappings:
      Namespace Name Mixin selector
      official a Ldrd$a;a()Ljava/lang/Object;
      intermediary method_29307 Lnet/minecraft/class_5330$class_5331;method_29307()Ljava/lang/Object;
      named build Lnet/minecraft/util/JsonSerializing$SerializerBuilder;build()Ljava/lang/Object;