Package blue.endless.jankson
Class Jankson.Builder
java.lang.Object
blue.endless.jankson.Jankson.Builder
- Enclosing class:
- Jankson
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAllows loading JSON files that do not contain root braces, as generated withbareRootObject.build()<A,B> Jankson.Builder registerDeserializer(Class<A> sourceClass, Class<B> targetClass, DeserializerFunction<A, B> function) <T> Jankson.BuilderregisterPrimitiveTypeAdapter(Class<T> clazz, Function<Object, T> adapter) Deprecated.<T> Jankson.BuilderregisterSerializer(Class<T> clazz, BiFunction<T, Marshaller, JsonElement> serializer) Registers a function to serialize an object into json.<T> Jankson.BuilderregisterTypeAdapter(Class<T> clazz, Function<JsonObject, T> adapter) Deprecated.please useregisterDeserializer(Class, Class, DeserializerFunction)instead.<T> Jankson.BuilderregisterTypeFactory(Class<T> clazz, Supplier<T> factory) Registers a factory that can generate empty objects of the specified type.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
registerTypeAdapter
@Deprecated public <T> Jankson.Builder registerTypeAdapter(Class<T> clazz, Function<JsonObject, T> adapter) Deprecated.please useregisterDeserializer(Class, Class, DeserializerFunction)instead.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 foradapter- 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) Deprecated.please useregisterDeserializer(Class, Class, DeserializerFunction)instead.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 foradapter- 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 forserializer- 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
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 forfactory- A Supplier which can create blank objects of class `clazz` for deserialization- Returns:
- This Builder for further modification.
-
allowBareRootObject
Allows loading JSON files that do not contain root braces, as generated withbareRootObject.- Returns:
- This Builder for further modification.
-
build
-
registerDeserializer(Class, Class, DeserializerFunction)instead.