Class Jankson.Builder

java.lang.Object
blue.endless.jankson.Jankson.Builder
Enclosing class:
Jankson

public static class Jankson.Builder extends Object
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • registerTypeAdapter

      @Deprecated public <T> Jankson.Builder registerTypeAdapter(Class<T> clazz, Function<JsonObject,T> adapter)
      Registers a deserializer that can transform a JsonObject into an instance of the specified class. Please note that these type adapters are unsuitable for generic types, as these types are erased during jvm execution.
      Parameters:
      clazz - The class to register deserialization for
      adapter - A function which takes a JsonObject and converts it into an equivalent object of the class `clazz`
      Returns:
      This Builder for further modification.
    • registerPrimitiveTypeAdapter

      @Deprecated public <T> Jankson.Builder registerPrimitiveTypeAdapter(Class<T> clazz, Function<Object,T> adapter)
      Registers a marshaller for primitive types. Most built-in json and java types are already supported, but this allows one to change the deserialization behavior of Json primitives. Please note that these adapters are not suitable for generic types, as these types are erased during jvm execution.
      Parameters:
      clazz - The class to register a type adapter for
      adapter - A function which takes a plain java object and converts it into the class `clazz`
      Returns:
      This Builder for further modification.
    • registerSerializer

      public <T> Jankson.Builder registerSerializer(Class<T> clazz, BiFunction<T,Marshaller,JsonElement> serializer)
      Registers a function to serialize an object into json. This can be useful if a class's serialized form is not meant to resemble its live-memory form.
      Parameters:
      clazz - The class to register a serializer for
      serializer - A function which takes the object and a Marshaller, and produces a serialized JsonElement
      Returns:
      This Builder for further modificaton.
    • registerDeserializer

      public <A, B> Jankson.Builder registerDeserializer(Class<A> sourceClass, Class<B> targetClass, DeserializerFunction<A,B> function)
    • registerTypeFactory

      public <T> Jankson.Builder registerTypeFactory(Class<T> clazz, Supplier<T> factory)
      Registers a factory that can generate empty objects of the specified type. Sometimes it's not practical to have a no-arg constructor available on an object, so the function to create blanks can be specified here.
      Parameters:
      clazz - The class to use an alternate factory for
      factory - A Supplier which can create blank objects of class `clazz` for deserialization
      Returns:
      This Builder for further modification.
    • allowBareRootObject

      public Jankson.Builder allowBareRootObject()
      Allows loading JSON files that do not contain root braces, as generated with bareRootObject.
      Returns:
      This Builder for further modification.
    • build

      public Jankson build()