TContext - used for library specialization. If unsure, use Objectpublic class DslJson<TContext> extends Object
During initialization DslJson will use ServiceLoader API to load registered services. This is done through `META-INF/services/com.dslplatform.json.CompiledJson` file.
DslJson can fallback to another serializer in case when it doesn't know how to handle specific type. This can be specified by Fallback interface during initialization.
If you wish to use compile time databinding @CompiledJson annotation must be specified on the target class or implicit reference to target class must exists from a class with @CompiledJson annotation.
Usage example:
DslJson<Object> dsl = new DslJson<>();
dsl.serialize(instance, OutputStream);
POJO pojo = dsl.deserialize(POJO.class, InputStream);
For best performance use serialization API with JsonWriter and byte[] as target. JsonWriter is reused via thread local variable. When custom JsonWriter's are used, reusing them will yield maximum performance. JsonWriter can be reused via reset methods. For best deserialization performance prefer byte[] API instead of InputStream API. JsonReader is reused via thread local variable. When custom JsonReaders are used, reusing them will yield maximum performance. JsonReader can be reused via process methods.
During deserialization TContext can be used to pass data into deserialized classes. This is useful when deserializing domain objects which require state or service provider. For example DSL Platform entities require service locator to be able to perform lazy load.
DslJson doesn't have a String or Reader API since it's optimized for processing bytes and streams. If you wish to process String, use String.getBytes("UTF-8") as argument for DslJson. Only UTF-8 is supported for encoding and decoding JSON.
DslJson<Object> dsl = new DslJson<>();
JsonWriter writer = dsl.newWriter();
dsl.serialize(writer, instance);
String json = writer.toString(); //JSON as string - avoid using JSON as Strings whenever possible
byte[] input = json.getBytes("UTF-8");
POJO pojo = dsl.deserialize(POJO.class, input, input.length);
| Modifier and Type | Class and Description |
|---|---|
static interface |
DslJson.ConverterFactory<T> |
static interface |
DslJson.Fallback<TContext> |
static class |
DslJson.Settings<TContext>
Configuration for DslJson options.
|
static class |
DslJson.SimpleStringCache
Simplistic string cache implementation.
|
| Modifier and Type | Field and Description |
|---|---|
boolean |
allowArrayFormat
When object supports array format, eg.
|
protected List<DslJson.ConverterFactory<JsonReader.BindObject>> |
binderFactories |
TContext |
context
The context of this instance.
|
protected DslJson.Fallback<TContext> |
fallback |
protected StringCache |
keyCache |
protected ThreadLocal<JsonReader> |
localReader |
protected ThreadLocal<JsonWriter> |
localWriter |
boolean |
omitDefaults
Should properties with default values be omitted from the resulting JSON?
This will leave out nulls, empty collections, zeros and other attributes with default values
which can be reconstructed from schema information
|
protected List<DslJson.ConverterFactory<JsonReader.ReadObject>> |
readerFactories |
protected StringCache |
valuesCache |
protected List<DslJson.ConverterFactory<JsonWriter.WriteObject>> |
writerFactories |
| Constructor and Description |
|---|
DslJson()
Simple initialization entry point.
|
DslJson(DslJson.Settings<TContext> settings)
Fully configurable entry point.
|
DslJson(TContext context,
boolean javaSpecifics,
DslJson.Fallback<TContext> fallback,
boolean omitDefaults,
StringCache keyCache,
Iterable<Configuration> serializers)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canDeserialize(Type manifest)
Check if DslJson knows how to deserialize a type.
|
boolean |
canSerialize(Type manifest)
Check if DslJson knows how to serialize a type.
|
protected IOException |
createErrorMessage(Class<?> manifest) |
<TResult> TResult |
deserialize(Class<TResult> manifest,
byte[] body,
int size)
Convenient deserialize API for working with bytes.
|
<TResult> TResult |
deserialize(Class<TResult> manifest,
InputStream stream)
Convenient deserialize API for working with streams.
|
<TResult> TResult |
deserialize(Class<TResult> manifest,
InputStream stream,
byte[] buffer)
Convenient deserialize API for working with streams.
|
protected <TResult> TResult |
deserialize(Class<TResult> manifest,
JsonReader json,
InputStream stream) |
<T> T |
deserialize(JsonReader.ReadObject<T> converter,
JsonReader<TContext> input)
Reusable deserialize API.
|
Object |
deserialize(Type manifest,
byte[] body,
int size)
Deserialize API for working with bytes.
|
Object |
deserialize(Type manifest,
InputStream stream)
Deserialize API for working with streams.
|
Object |
deserialize(Type manifest,
InputStream stream,
byte[] buffer)
Deserialize API for working with streams.
|
<TResult> List<TResult> |
deserializeList(Class<TResult> manifest,
byte[] body,
int size)
Convenient deserialize list API for working with bytes.
|
<TResult> List<TResult> |
deserializeList(Class<TResult> manifest,
InputStream stream)
Convenient deserialize list API for working with streams.
|
<TResult> List<TResult> |
deserializeList(Class<TResult> manifest,
InputStream stream,
byte[] buffer)
This is deprecated to avoid using it.
|
protected <TResult> List<TResult> |
deserializeList(Class<TResult> manifest,
JsonReader<TContext> json,
InputStream stream) |
static ArrayList<Object> |
deserializeList(JsonReader reader)
Deprecated.
|
static LinkedHashMap<String,Object> |
deserializeMap(JsonReader reader)
Deprecated.
|
static Object |
deserializeObject(JsonReader reader)
Deprecated.
|
protected Object |
deserializeWith(Type manifest,
JsonReader json) |
Object |
getDefault(Type manifest) |
protected JsonReader.ReadJsonObject<JsonObject> |
getObjectReader(Class<?> manifest) |
Set<Type> |
getRegisteredBinders() |
Map<Class<? extends Annotation>,Boolean> |
getRegisteredCreatorMarkers() |
Set<Type> |
getRegisteredDecoders() |
Set<Type> |
getRegisteredEncoders() |
<TResult> Iterator<TResult> |
iterateOver(Class<TResult> manifest,
InputStream stream)
Streaming API for collection deserialization.
|
<TResult> Iterator<TResult> |
iterateOver(Class<TResult> manifest,
InputStream stream,
byte[] buffer)
Streaming API for collection deserialization.
|
protected <TResult> Iterator<TResult> |
iterateOver(Class<TResult> manifest,
JsonReader json,
InputStream stream) |
<T> void |
iterateOver(Iterator<T> iterator,
Class<T> manifest,
OutputStream stream,
JsonWriter writer)
Streaming API for collection serialization.
|
<T> void |
iterateOver(Iterator<T> iterator,
OutputStream stream,
JsonWriter writer)
Streaming API for collection serialization.
|
JsonReader<TContext> |
newReader()
Create a reader bound to this DSL-JSON.
|
JsonReader<TContext> |
newReader(byte[] bytes)
Create a reader bound to this DSL-JSON.
|
JsonReader<TContext> |
newReader(byte[] bytes,
int length)
Create a reader bound to this DSL-JSON.
|
JsonReader<TContext> |
newReader(byte[] bytes,
int length,
char[] tmp)
Create a reader bound to this DSL-JSON.
|
JsonReader<TContext> |
newReader(InputStream stream,
byte[] buffer)
Create a reader bound to this DSL-JSON.
|
JsonReader<TContext> |
newReader(String input)
Deprecated.
|
JsonWriter |
newWriter()
Create a writer bound to this DSL-JSON.
|
JsonWriter |
newWriter(byte[] buffer)
Create a writer bound to this DSL-JSON.
|
JsonWriter |
newWriter(int size)
Create a writer bound to this DSL-JSON.
|
<T,S extends T> |
registerBinder(Class<T> manifest,
JsonReader.BindObject<S> binder)
Register custom binder for specific type (JSON -> instance conversion).
|
void |
registerBinder(Type manifest,
JsonReader.BindObject<?> binder)
Register custom binder for specific type (JSON -> instance conversion).
|
boolean |
registerBinderFactory(DslJson.ConverterFactory<? extends JsonReader.BindObject> factory) |
<T> void |
registerDefault(Class<T> manifest,
T instance) |
<T,S extends T> |
registerReader(Class<T> manifest,
JsonReader.ReadObject<S> reader)
Register custom reader for specific type (JSON -> instance conversion).
|
JsonReader.ReadObject |
registerReader(Type manifest,
JsonReader.ReadObject<?> reader)
Register custom reader for specific type (JSON -> instance conversion).
|
boolean |
registerReaderFactory(DslJson.ConverterFactory<? extends JsonReader.ReadObject> factory) |
<T> void |
registerWriter(Class<T> manifest,
JsonWriter.WriteObject<T> writer)
Register custom writer for specific type (instance -> JSON conversion).
|
JsonWriter.WriteObject |
registerWriter(Type manifest,
JsonWriter.WriteObject<?> writer)
Register custom writer for specific type (instance -> JSON conversion).
|
boolean |
registerWriterFactory(DslJson.ConverterFactory<? extends JsonWriter.WriteObject> factory) |
<T extends JsonObject> |
serialize(JsonWriter writer,
Collection<T> collection)
Deprecated.
|
<T extends JsonObject> |
serialize(JsonWriter writer,
List<T> list)
Deprecated.
|
void |
serialize(JsonWriter writer,
Object value)
Main serialization API.
|
<T extends JsonObject> |
serialize(JsonWriter writer,
T[] array)
Deprecated.
|
<T extends JsonObject> |
serialize(JsonWriter writer,
T[] array,
int len)
Deprecated.
|
boolean |
serialize(JsonWriter writer,
Type manifest,
Object value)
Generic serialize API.
|
void |
serialize(Object value,
OutputStream stream)
Convenient serialize API.
|
void |
serializeMap(Map<String,Object> value,
JsonWriter sw) |
<T> JsonReader.BindObject<T> |
tryFindBinder(Class<T> manifest)
Try to find registered binder for provided type.
|
JsonReader.BindObject<?> |
tryFindBinder(Type manifest)
Try to find registered binder for provided type.
|
<T> JsonReader.ReadObject<T> |
tryFindReader(Class<T> manifest)
Try to find registered reader for provided type.
|
JsonReader.ReadObject<?> |
tryFindReader(Type manifest)
Try to find registered reader for provided type.
|
<T> JsonWriter.WriteObject<T> |
tryFindWriter(Class<T> manifest)
Try to find registered writer for provided type.
|
JsonWriter.WriteObject<?> |
tryFindWriter(Type manifest)
Try to find registered writer for provided type.
|
@Nullable public final TContext context
@Nullable protected final DslJson.Fallback<TContext> fallback
public final boolean omitDefaults
public final boolean allowArrayFormat
protected final StringCache keyCache
protected final StringCache valuesCache
protected final List<DslJson.ConverterFactory<JsonWriter.WriteObject>> writerFactories
protected final List<DslJson.ConverterFactory<JsonReader.ReadObject>> readerFactories
protected final List<DslJson.ConverterFactory<JsonReader.BindObject>> binderFactories
protected final ThreadLocal<JsonWriter> localWriter
protected final ThreadLocal<JsonReader> localReader
public DslJson()
@Deprecated public DslJson(@Nullable TContext context, boolean javaSpecifics, @Nullable DslJson.Fallback<TContext> fallback, boolean omitDefaults, @Nullable StringCache keyCache, Iterable<Configuration> serializers)
context - context instance which can be provided to deserialized objects. Use null if not surejavaSpecifics - register Java graphics specific classes such as java.awt.Point, Image, ...fallback - in case of unsupported type, try serialization/deserialization through external APIomitDefaults - should serialization produce minified JSON (omit nulls and default values)keyCache - parsed keys can be cached (this is only used in small subset of parsing)serializers - additional serializers/deserializers which will be immediately registered into readers/writerspublic DslJson(DslJson.Settings<TContext> settings)
settings - DSL-JSON configurationpublic JsonWriter newWriter()
public JsonWriter newWriter(int size)
size - initial buffer sizepublic JsonWriter newWriter(byte[] buffer)
buffer - initial bufferpublic JsonReader<TContext> newReader()
public JsonReader<TContext> newReader(byte[] bytes)
bytes - input bytespublic JsonReader<TContext> newReader(byte[] bytes, int length)
bytes - input byteslength - use input bytes up to specified lengthpublic JsonReader<TContext> newReader(byte[] bytes, int length, char[] tmp)
bytes - input byteslength - use input bytes up to specified lengthtmp - string parsing bufferpublic JsonReader<TContext> newReader(InputStream stream, byte[] buffer) throws IOException
stream - input streambuffer - temporary bufferIOException - unable to read from stream@Deprecated public JsonReader<TContext> newReader(String input)
input - JSON stringpublic <T> void registerDefault(Class<T> manifest, T instance)
public boolean registerWriterFactory(DslJson.ConverterFactory<? extends JsonWriter.WriteObject> factory)
public boolean registerReaderFactory(DslJson.ConverterFactory<? extends JsonReader.ReadObject> factory)
public boolean registerBinderFactory(DslJson.ConverterFactory<? extends JsonReader.BindObject> factory)
public final Map<Class<? extends Annotation>,Boolean> getRegisteredCreatorMarkers()
public <T,S extends T> void registerReader(Class<T> manifest, @Nullable JsonReader.ReadObject<S> reader)
Types registered through @CompiledJson annotation should be registered automatically through ServiceLoader.load method and you should not be registering them manually.
If null is registered for a reader this will disable deserialization of specified type
T - typeS - type or subtypemanifest - specified typereader - provide custom implementation for reading JSON into an object instance@Nullable public JsonReader.ReadObject registerReader(Type manifest, @Nullable JsonReader.ReadObject<?> reader)
Types registered through @CompiledJson annotation should be registered automatically through ServiceLoader.load method and you should not be registering them manually.
If null is registered for a reader this will disable deserialization of specified type
manifest - specified typereader - provide custom implementation for reading JSON into an object instancepublic <T,S extends T> void registerBinder(Class<T> manifest, @Nullable JsonReader.BindObject<S> binder)
Types registered through @CompiledJson annotation should be registered automatically through ServiceLoader.load method and you should not be registering them manually.
If null is registered for a binder this will disable binding of specified type
T - typeS - type or subtypemanifest - specified typebinder - provide custom implementation for binding JSON to an object instancepublic void registerBinder(Type manifest, @Nullable JsonReader.BindObject<?> binder)
Types registered through @CompiledJson annotation should be registered automatically through ServiceLoader.load method and you should not be registering them manually.
If null is registered for a binder this will disable binding of specified type
manifest - specified typebinder - provide custom implementation for binding JSON to an object instancepublic <T> void registerWriter(Class<T> manifest, @Nullable JsonWriter.WriteObject<T> writer)
Types registered through @CompiledJson annotation should be registered automatically through ServiceLoader.load method and you should not be registering them manually.
If null is registered for a writer this will disable serialization of specified type
T - typemanifest - specified typewriter - provide custom implementation for writing JSON from object instance@Nullable public JsonWriter.WriteObject registerWriter(Type manifest, @Nullable JsonWriter.WriteObject<?> writer)
Types registered through @CompiledJson annotation should be registered automatically through ServiceLoader.load method and you should not be registering them manually.
If null is registered for a writer this will disable serialization of specified type
manifest - specified typewriter - provide custom implementation for writing JSON from object instance@Nullable public JsonWriter.WriteObject<?> tryFindWriter(Type manifest)
Writer is used for conversion from object instance into JSON representation.
manifest - specified type@Nullable public JsonReader.ReadObject<?> tryFindReader(Type manifest)
If you wish to use alternative reader for specific type, register it manually with something along the lines of
DslJson dslJson = ...
dslJson.registerReader(Interface.class, dslJson.tryFindReader(Implementation.class));
manifest - specified type@Nullable public JsonReader.BindObject<?> tryFindBinder(Type manifest)
If you wish to use alternative binder for specific type, register it manually with something along the lines of
DslJson dslJson = ...
dslJson.registerBinder(Interface.class, dslJson.tryFindBinder(Implementation.class));
manifest - specified type@Nullable public <T> JsonWriter.WriteObject<T> tryFindWriter(Class<T> manifest)
Writer is used for conversion from object instance into JSON representation.
T - specified typemanifest - specified class@Nullable public <T> JsonReader.ReadObject<T> tryFindReader(Class<T> manifest)
If you wish to use alternative reader for specific type, register it manually with something along the lines of
DslJson dslJson = ...
dslJson.registerReader(Interface.class, dslJson.tryFindReader(Implementation.class));
T - specified typemanifest - specified class@Nullable public <T> JsonReader.BindObject<T> tryFindBinder(Class<T> manifest)
If you wish to use alternative binder for specific type, register it manually with something along the lines of
DslJson dslJson = ...
dslJson.registerBinder(Interface.class, dslJson.tryFindBinder(Implementation.class));
T - specified typemanifest - specified class@Nullable protected final JsonReader.ReadJsonObject<JsonObject> getObjectReader(Class<?> manifest)
public void serializeMap(Map<String,Object> value, JsonWriter sw) throws IOException
IOException@Deprecated @Nullable public static Object deserializeObject(JsonReader reader) throws IOException
IOException@Deprecated public static ArrayList<Object> deserializeList(JsonReader reader) throws IOException
reader - JSON readerIOException - error during parsing@Deprecated public static LinkedHashMap<String,Object> deserializeMap(JsonReader reader) throws IOException
reader - JSON readerIOException - error during parsingpublic final boolean canSerialize(Type manifest)
manifest - type to checkpublic final boolean canDeserialize(Type manifest)
manifest - type to check@Nullable public <T> T deserialize(JsonReader.ReadObject<T> converter, JsonReader<TContext> input) throws IOException
This is mostly convenience API since it starts the processing of the JSON by calling getNextToken on JsonReader, checks for null and calls converter.read(input).
T - specified typeconverter - target readerinput - input JSONIOException - error during deserialization@Nullable public <TResult> TResult deserialize(Class<TResult> manifest, byte[] body, int size) throws IOException
Since JSON is often though of as a series of char, most libraries will convert inputs into a sequence of chars and do processing on them. DslJson will treat input as a sequence of bytes which allows for various optimizations.
TResult - target typemanifest - target typebody - input JSONsize - lengthIOException - error during deserialization@Nullable public Object deserialize(Type manifest, byte[] body, int size) throws IOException
Since JSON is often though of as a series of char, most libraries will convert inputs into a sequence of chars and do processing on them. DslJson will treat input as a sequence of bytes which allows for various optimizations.
manifest - target typebody - input JSONsize - lengthIOException - error during deserialization@Nullable protected Object deserializeWith(Type manifest, JsonReader json) throws IOException
IOExceptionprotected IOException createErrorMessage(Class<?> manifest)
@Nullable public <TResult> List<TResult> deserializeList(Class<TResult> manifest, byte[] body, int size) throws IOException
Since JSON is often though of as a series of char, most libraries will convert inputs into a sequence of chars and do processing on them. DslJson will treat input as a sequence of bytes which allows for various optimizations.
TResult - target element typemanifest - target typebody - input JSONsize - lengthIOException - error during deserialization@Nullable public <TResult> List<TResult> deserializeList(Class<TResult> manifest, InputStream stream, byte[] buffer) throws IOException
Since JSON is often though of as a series of char, most libraries will convert inputs into a sequence of chars and do processing on them. DslJson will treat input as a sequence of bytes which allows for various optimizations.
When working on InputStream DslJson will process JSON in chunks of byte[] inputs. Provided buffer will be used as input for partial processing.
For best performance buffer should be reused.
TResult - target element typemanifest - target typestream - input JSONbuffer - buffer used for InputStream -> byte[] conversionIOException - error during deserialization@Nullable public <TResult> List<TResult> deserializeList(Class<TResult> manifest, InputStream stream) throws IOException
Since JSON is often though of as a series of char, most libraries will convert inputs into a sequence of chars and do processing on them. DslJson will treat input as a sequence of bytes which allows for various optimizations.
When working on InputStream DslJson will process JSON in chunks of byte[] inputs.
TResult - target element typemanifest - target typestream - input JSONIOException - error during deserialization@Nullable protected <TResult> List<TResult> deserializeList(Class<TResult> manifest, JsonReader<TContext> json, InputStream stream) throws IOException
IOException@Nullable public <TResult> TResult deserialize(Class<TResult> manifest, InputStream stream, byte[] buffer) throws IOException
Since JSON is often though of as a series of char, most libraries will convert inputs into a sequence of chars and do processing on them. DslJson will treat input as a sequence of bytes which allows for various optimizations.
When working on InputStream DslJson will process JSON in chunks of byte[] inputs. Provided buffer will be used as input for partial processing.
For best performance buffer should be reused.
TResult - target typemanifest - target typestream - input JSONbuffer - buffer used for InputStream -> byte[] conversionIOException - error during deserialization@Nullable public <TResult> TResult deserialize(Class<TResult> manifest, InputStream stream) throws IOException
Since JSON is often though of as a series of char, most libraries will convert inputs into a sequence of chars and do processing on them. DslJson will treat input as a sequence of bytes which allows for various optimizations.
When working on InputStream DslJson will process JSON in chunks of byte[] inputs.
TResult - target typemanifest - target typestream - input JSONIOException - error during deserialization@Nullable protected <TResult> TResult deserialize(Class<TResult> manifest, JsonReader json, InputStream stream) throws IOException
IOException@Nullable public Object deserialize(Type manifest, InputStream stream, byte[] buffer) throws IOException
Since JSON is often though of as a series of char, most libraries will convert inputs into a sequence of chars and do processing on them. DslJson will treat input as a sequence of bytes which allows for various optimizations.
When working on InputStream DslJson will process JSON in chunks of byte[] inputs. Provided buffer will be used as input for partial processing.
For best performance buffer should be reused.
manifest - target typestream - input JSONbuffer - buffer used for InputStream -> byte[] conversionIOException - error during deserialization@Nullable public Object deserialize(Type manifest, InputStream stream) throws IOException
Since JSON is often though of as a series of char, most libraries will convert inputs into a sequence of chars and do processing on them.
When working on InputStream DslJson will process JSON in chunks of byte[] inputs.
manifest - target typestream - input JSONIOException - error during deserialization@Nullable public <TResult> Iterator<TResult> iterateOver(Class<TResult> manifest, InputStream stream) throws IOException
Useful for processing very large streams if only one instance from collection is required at once.
Stream will be processed in chunks of specified buffer byte[]. It will block on reading until buffer is full or end of stream is detected.
TResult - type infomanifest - type infostream - JSON data streamIOException - if reader is not found or there is an error processing input stream@Nullable public <TResult> Iterator<TResult> iterateOver(Class<TResult> manifest, InputStream stream, byte[] buffer) throws IOException
Useful for processing very large streams if only one instance from collection is required at once.
Stream will be processed in chunks of specified buffer byte[]. It will block on reading until buffer is full or end of stream is detected.
TResult - type infomanifest - type infostream - JSON data streambuffer - size of processing chunkIOException - if reader is not found or there is an error processing input stream@Nullable protected <TResult> Iterator<TResult> iterateOver(Class<TResult> manifest, JsonReader json, InputStream stream) throws IOException
IOExceptionpublic <T> void iterateOver(Iterator<T> iterator, OutputStream stream, @Nullable JsonWriter writer) throws IOException
It will iterate over entire iterator and serialize each instance into target output stream. After each instance serialization it will copy JSON into target output stream. During each serialization reader will be looked up based on next() instance which allows serializing collection with different types. If collection contains all instances of the same type, prefer the other streaming API.
If reader is not found an IOException will be thrown
If JsonWriter is provided it will be used, otherwise a new instance will be internally created.
T - input data typeiterator - input datastream - target JSON streamwriter - temporary buffer for serializing a single item. Can be nullIOException - reader is not found, there is an error during serialization or problem with writing to target streampublic <T> void iterateOver(Iterator<T> iterator, Class<T> manifest, OutputStream stream, @Nullable JsonWriter writer) throws IOException
It will iterate over entire iterator and serialize each instance into target output stream. After each instance serialization it will copy JSON into target output stream.
If reader is not found an IOException will be thrown
If JsonWriter is provided it will be used, otherwise a new instance will be internally created.
T - input data typeiterator - input datamanifest - type of elements in collectionstream - target JSON streamwriter - temporary buffer for serializing a single item. Can be nullIOException - reader is not found, there is an error during serialization or problem with writing to target stream@Deprecated public <T extends JsonObject> void serialize(JsonWriter writer, @Nullable T[] array)
T - typewriter - writerarray - items@Deprecated public <T extends JsonObject> void serialize(JsonWriter writer, T[] array, int len)
T - typewriter - writerarray - itemslen - part of array@Deprecated public <T extends JsonObject> void serialize(JsonWriter writer, @Nullable List<T> list)
T - typewriter - writerlist - items@Deprecated public <T extends JsonObject> void serialize(JsonWriter writer, @Nullable Collection<T> collection)
T - typewriter - writercollection - itemspublic boolean serialize(JsonWriter writer, Type manifest, @Nullable Object value)
Resulting JSON will be written into provided writer argument. In case of successful serialization true will be returned.
For best performance writer argument should be reused.
writer - where to write resulting JSONmanifest - type manifestvalue - instance to serializepublic final void serialize(@Nullable Object value, OutputStream stream) throws IOException
value - instance to serializestream - where to write resulting JSONIOException - error when unable to serialize instancepublic final void serialize(JsonWriter writer, @Nullable Object value) throws IOException
JsonWriter contains a growable byte[] where JSON will be serialized. After serialization JsonWriter can be copied into OutputStream or it's byte[] can be obtained
For best performance reuse `JsonWriter` or even better call `JsonWriter.WriteObject` directly
writer - where to write resulting JSONvalue - object instance to serializeIOException - error when unable to serialize instanceCopyright © 2023. All rights reserved.