Package name.martingeisse.grumpyjson
Class StructuralJsonEngine
java.lang.Object
name.martingeisse.grumpyjson.StructuralJsonEngine
- Direct Known Subclasses:
JsonEngine
This base class of
JsonEngine implements the "conversion" part of the JSON engine and can be used if
actual (de-)serialization from and to JSON syntax is not needed. In turn, it does not have any dependency on any
concrete JSON syntax implementation such as Gson or Jackson, but operates purely on the structural JSON model
defined in the json_model subpackage.
Please read the JsonEngine documentation for usage instructions.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new JSON engine with standard converters registered. -
Method Summary
Modifier and TypeMethodDescriptionfinal <T> Tdeserialize(JsonElement source, Class<T> clazz) deserializes JSON from aJsonElement.final Objectdeserialize(JsonElement source, Type type) deserializes JSON from aJsonElement.final <T> Tdeserialize(JsonElement source, TypeToken<T> typeToken) deserializes JSON from aJsonElement.final JsonDeserializerRegistryGetter method for the registry for deserializers.final JsonRegistriesGetter method for the registries for converters.final JsonSerializerRegistryGetter method for the registry for serializers.final voidregisterDeserializer(JsonDeserializer deserializer) Registers the specified deserializer.final <T extends JsonSerializer<?> & JsonDeserializer>
voidregisterDualConverter(T converter) Registers the specified dual converter.final voidregisterSerializer(JsonSerializer<?> serializer) Registers the specified serializer.voidseal()Seals this JSON engine, moving from the configuration phase to the run-time phase.final booleansupportsClassForSerialization(Class<?> clazz) Checks whether the specified class is supported for serialization by this enginefinal booleanChecks whether the specified type is supported for deserialization by this enginefinal JsonElementtoJsonElement(Object value) Turns a value into aJsonElement.
-
Constructor Details
-
StructuralJsonEngine
public StructuralJsonEngine()Creates a new JSON engine with standard converters registered.
-
-
Method Details
-
registerSerializer
Registers the specified serializer.- Parameters:
serializer- the serializer to register
-
registerDeserializer
Registers the specified deserializer.- Parameters:
deserializer- the deserializer to register
-
registerDualConverter
public final <T extends JsonSerializer<?> & JsonDeserializer> void registerDualConverter(T converter) Registers the specified dual converter.- Type Parameters:
T- the dual converter type which must implement bothJsonSerializerandJsonDeserializer- Parameters:
converter- the dual converter to register
-
getRegistries
Getter method for the registries for converters.- Returns:
- the registries
-
getSerializerRegistry
Getter method for the registry for serializers.- Returns:
- the registry for serializers
-
getDeserializerRegistry
Getter method for the registry for deserializers.- Returns:
- the registry for deserializers
-
seal
public void seal()Seals this JSON engine, moving from the configuration phase to the run-time phase. -
supportsClassForSerialization
Checks whether the specified class is supported for serialization by this engine- Parameters:
clazz- the class to check- Returns:
- true if supported, false if not
-
supportsTypeForDeserialization
Checks whether the specified type is supported for deserialization by this engine- Parameters:
type- the type to check- Returns:
- true if supported, false if not
-
deserialize
public final <T> T deserialize(JsonElement source, Class<T> clazz) throws JsonDeserializationException deserializes JSON from aJsonElement.- Type Parameters:
T- the static target type- Parameters:
source- the source elementclazz- the target type to deserialize to- Returns:
- the deserialized value
- Throws:
JsonDeserializationException- if the JSON does not match the target type
-
deserialize
public final <T> T deserialize(JsonElement source, TypeToken<T> typeToken) throws JsonDeserializationException deserializes JSON from aJsonElement.- Type Parameters:
T- the static target type- Parameters:
source- the source elementtypeToken- a type token for the target type to deserialize to- Returns:
- the deserialized value
- Throws:
JsonDeserializationException- if the JSON does not match the target type
-
deserialize
deserializes JSON from aJsonElement.- Parameters:
source- the source elementtype- the target type to deserialize to- Returns:
- the deserialized value
- Throws:
JsonDeserializationException- if the JSON does not match the target type
-
toJsonElement
Turns a value into aJsonElement.- Parameters:
value- the value to convert- Returns:
- the JSON element
- Throws:
JsonSerializationException- if the value is in an inconsistent state or a state that cannot be turned into JSON
-