Package name.martingeisse.grumpyjson
Class GsonBasedJsonEngine
java.lang.Object
name.martingeisse.grumpyjson.StructuralJsonEngine
name.martingeisse.grumpyjson.JsonEngine
name.martingeisse.grumpyjson.GsonBasedJsonEngine
GSON-based implementation of
JsonEngine.-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new JSON engine with standard converters registered. -
Method Summary
Modifier and TypeMethodDescription<T> Tdeserialize(InputStream source, Class<T> clazz) deserializes JSON from anInputStream.deserialize(InputStream source, Type type) deserializes JSON from anInputStream.<T> Tdeserialize(InputStream source, TypeToken<T> typeToken) deserializes JSON from anInputStream.<T> Tdeserialize(Reader source, Class<T> clazz) deserializes JSON from anReader.deserialize(Reader source, Type type) deserializes JSON from anReader.<T> Tdeserialize(Reader source, TypeToken<T> typeToken) deserializes JSON from anReader.<T> Tdeserialize(String source, Class<T> clazz) deserializes JSON from aString.deserialize(String source, Type type) deserializes JSON from aString.<T> Tdeserialize(String source, TypeToken<T> typeToken) deserializes JSON from aString.serializeToString(Object value) Turns a value into a JSON string.voidwriteTo(Object value, OutputStream destination) Turns a value into JSON that is written to an output stream.voidTurns a value into JSON that is written to a writer.Methods inherited from class name.martingeisse.grumpyjson.StructuralJsonEngine
deserialize, deserialize, deserialize, getDeserializerRegistry, getRegistries, getSerializerRegistry, registerDeserializer, registerDualConverter, registerSerializer, seal, supportsClassForSerialization, supportsTypeForDeserialization, toJsonElement
-
Constructor Details
-
GsonBasedJsonEngine
public GsonBasedJsonEngine()Creates a new JSON engine with standard converters registered.
-
-
Method Details
-
deserialize
Description copied from class:JsonEnginedeserializes JSON from aString.- Specified by:
deserializein classJsonEngine- Type Parameters:
T- the static target type- Parameters:
source- the source stringclazz- the target type to deserialize to- Returns:
- the deserialized value
- Throws:
JsonDeserializationException- if the JSON is malformed or does not match the target type
-
deserialize
Description copied from class:JsonEnginedeserializes JSON from aString.- Specified by:
deserializein classJsonEngine- Type Parameters:
T- the static target type- Parameters:
source- the source stringtypeToken- a type token for the target type to deserialize to- Returns:
- the deserialized value
- Throws:
JsonDeserializationException- if the JSON is malformed or does not match the target type
-
deserialize
Description copied from class:JsonEnginedeserializes JSON from aString.- Specified by:
deserializein classJsonEngine- Parameters:
source- the source stringtype- the target type to deserialize to- Returns:
- the deserialized value
- Throws:
JsonDeserializationException- if the JSON is malformed or does not match the target type
-
deserialize
Description copied from class:JsonEnginedeserializes JSON from anInputStream. As demanded by the MIME type application/json, the input must be UTF-8 encoded.- Specified by:
deserializein classJsonEngine- Type Parameters:
T- the static target type- Parameters:
source- the source streamclazz- the target type to deserialize to- Returns:
- the deserialized value
- Throws:
JsonDeserializationException- if the JSON is malformed or does not match the target type
-
deserialize
public <T> T deserialize(InputStream source, TypeToken<T> typeToken) throws JsonDeserializationException Description copied from class:JsonEnginedeserializes JSON from anInputStream. As demanded by the MIME type application/json, the input must be UTF-8 encoded.- Specified by:
deserializein classJsonEngine- Type Parameters:
T- the static target type- Parameters:
source- the source streamtypeToken- a type token for the target type to deserialize to- Returns:
- the deserialized value
- Throws:
JsonDeserializationException- if the JSON is malformed or does not match the target type
-
deserialize
Description copied from class:JsonEnginedeserializes JSON from anInputStream. As demanded by the MIME type application/json, the input must be UTF-8 encoded.- Specified by:
deserializein classJsonEngine- Parameters:
source- the source streamtype- the target type to deserialize to- Returns:
- the deserialized value
- Throws:
JsonDeserializationException- if the JSON is malformed or does not match the target type
-
deserialize
Description copied from class:JsonEnginedeserializes JSON from anReader.- Specified by:
deserializein classJsonEngine- Type Parameters:
T- the static target type- Parameters:
source- the source readerclazz- the target type to deserialize to- Returns:
- the deserialized value
- Throws:
JsonDeserializationException- if the JSON is malformed or does not match the target type
-
deserialize
Description copied from class:JsonEnginedeserializes JSON from anReader.- Specified by:
deserializein classJsonEngine- Type Parameters:
T- the static target type- Parameters:
source- the source readertypeToken- a type token for the target type to deserialize to- Returns:
- the deserialized value
- Throws:
JsonDeserializationException- if the JSON is malformed or does not match the target type
-
deserialize
Description copied from class:JsonEnginedeserializes JSON from anReader.- Specified by:
deserializein classJsonEngine- Parameters:
source- the source readertype- the target type to deserialize to- Returns:
- the deserialized value
- Throws:
JsonDeserializationException- if the JSON is malformed or does not match the target type
-
serializeToString
Description copied from class:JsonEngineTurns a value into a JSON string.- Specified by:
serializeToStringin classJsonEngine- Parameters:
value- the value to serialize- Returns:
- the JSON string
- Throws:
JsonSerializationException- if the value is in an inconsistent state or a state that cannot be turned into JSON
-
writeTo
Description copied from class:JsonEngineTurns a value into JSON that is written to an output stream. As demanded by the MIME type application/json, the output will be UTF-8 encoded.- Specified by:
writeToin classJsonEngine- Parameters:
value- the value to convertdestination- the stream to write to- Throws:
JsonSerializationException- if the value is in an inconsistent state or a state that cannot be turned into JSON
-
writeTo
Description copied from class:JsonEngineTurns a value into JSON that is written to a writer.- Specified by:
writeToin classJsonEngine- Parameters:
value- the value to convertdestination- the writer to write to- Throws:
JsonSerializationException- if the value is in an inconsistent state or a state that cannot be turned into JSON
-