public class JSONSerializer extends com.streamscape.omf.serializer.AbstractSerializer implements TextSerializer
Title: Object Mediation Framework
Description: JSON serializer.
JsonNotation
and JsonNotationLevel
notations
and use Fabric Runtime alias manager ObjectMediationAliasManager
.
Copyright: Copyright (c) 2016
Company: StreamScape Technologies
Modifier and Type | Class and Description |
---|---|
static class |
JSONSerializer.AbstractJsonSerializerBuilder |
static interface |
JSONSerializer.JsonSerializerBuilder |
static class |
JSONSerializer.JsonSerializerBuilderImpl |
DEFAULT_SERIAL_VERSION_ID
Modifier and Type | Method and Description |
---|---|
static JSONSerializer.JsonSerializerBuilderImpl |
builder() |
static JSONSerializer.JsonSerializerBuilderImpl |
builder(JSONSerializer template) |
JsonGenerator |
createGenerator(java.io.OutputStream output,
JsonEncoding encoding) |
JsonGenerator |
createGenerator(java.io.OutputStream output,
JsonEncoding encoding,
boolean useSamePrettyPrinter) |
JsonParser |
createParser(byte[] content) |
JsonParser |
createParser(java.lang.String content) |
java.lang.Object |
deserialize(byte[] buffer)
Deserializes instance of a Java object from byte array.
|
java.lang.Object |
deserialize(java.lang.Class objectClass,
JsonParser parser)
Deserializes instance of Java object from a
buffer . |
java.lang.Object |
deserialize(java.io.DataInputStream stream)
Deserializes instance of Java object from a
DataOutputStream . |
java.lang.Object |
deserialize(JsonParser parser)
Deserializes instance of a Java object from string.
|
java.lang.Object |
deserialize(java.io.Reader reader)
Deserializes instance of Java object from a
Reader . |
java.lang.Object |
deserialize(java.lang.String buffer)
Deserializes instance of a Java object from string.
|
java.lang.Object |
deserialize(java.lang.String semanticType,
byte[] buffer)
Deserializes instance of a Java object from byte array.
|
java.lang.Object |
deserialize(java.lang.String semanticType,
java.io.DataInputStream stream)
Deserializes instance of Java object from a
DataOutputStream . |
java.lang.Object |
deserialize(java.lang.String semanticType,
JsonParser parser)
Deserializes instance of a Java object from string.
|
java.lang.Object |
deserialize(java.lang.String semanticType,
java.io.Reader reader)
Deserializes instance of Java object from a
Reader . |
java.lang.Object |
deserialize(java.lang.String semanticType,
java.lang.String buffer)
Deserializes instance of a Java object from string.
|
void |
failOnUnknownElements(boolean flag) |
static JSONSerializer |
getContextJsonSerializer() |
JsonNotation |
getJsonNotation() |
java.util.EnumSet |
getJsonNotationLevel() |
java.lang.String |
getName()
Returns the name of the serializer.
|
boolean |
getPrettyPrint() |
boolean |
isSkipNulls() |
static boolean |
isUnquotedString(java.lang.String buffer) |
java.lang.Class |
resolveSemanticClass(java.lang.String semanticType) |
java.lang.String |
serialize(java.lang.Object obj)
Serializes an instance of an arbitrary
Java Object into string. |
void |
serialize(java.lang.Object obj,
JsonGenerator generator)
Serializes instance of a Java object into
Writer . |
void |
serialize(java.lang.Object obj,
java.io.Writer writer)
Serializes instance of a Java object into
Writer . |
java.lang.String |
serialize(java.lang.String semanticType,
java.lang.Object obj)
Serializes an instance of an arbitrary
Java Object into string. |
void |
serialize(java.lang.String semanticType,
java.lang.Object obj,
java.io.DataOutputStream stream)
Serializes instance of a Java object into
DataOutputStream . |
void |
serialize(java.lang.String semanticType,
java.lang.Object obj,
java.io.Writer writer)
Serializes instance of a Java object into
Writer . |
void |
setClassLoader(java.lang.ClassLoader classLoader)
Sets the class loader for this serializer, ensuring that any operations will find the classes that they need
to work on.
|
JSONSerializer |
withPrettyPrint(boolean prettyPrintEnabled) |
destroy, getClassLoader
clone, getSerialVersionUID
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
destroy, getClassLoader
public java.lang.String getName()
Serializer
getName
in interface Serializer
public JsonNotation getJsonNotation()
public java.util.EnumSet getJsonNotationLevel()
public boolean isSkipNulls()
public void setClassLoader(java.lang.ClassLoader classLoader)
Serializer
Semantic Types
may have been registered (aliased) at startup whose classes are not reachable by the
system thread's class loader. It is possible to set the class loader for the duration
of a serialization or deserialization operation allowing Serializer to access the needed
loader and it's classes. However, it is also possible to erroneously supply an isolated
or non-chained loader that makes the underlying classes required by Serializer internals
inaccessible.setClassLoader
in interface Serializer
setClassLoader
in class com.streamscape.omf.serializer.AbstractSerializer
classLoader
- the loader to be set.public JSONSerializer withPrettyPrint(boolean prettyPrintEnabled)
public boolean getPrettyPrint()
public java.lang.String serialize(java.lang.Object obj) throws SerializerException
TextSerializer
Java Object
into string. The object may be
a plain Java object or an instance of a StructuredDataObject
.
The object must be defined as a known Semantic Type and all of its elements must be registered
in the Alias Map
.serialize
in interface TextSerializer
obj
- the object to be serialized.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public void serialize(java.lang.Object obj, java.io.Writer writer) throws SerializerException
TextSerializer
Writer
. The object may be an
instance of StructuredDataObject
or a standard Java object. The actual output format is
implementation specific. The object must be defined as a known Semantic Type and all of its elements
must be registered in the Alias Map
.serialize
in interface TextSerializer
obj
- the object to be serialized.writer
- the writer that holds the serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public void serialize(java.lang.Object obj, JsonGenerator generator) throws JSONSerializerException
TextSerializer
Writer
. The object may be an
instance of StructuredDataObject
or a standard Java object. The actual output format is
implementation specific. The object must be defined as a known Semantic Type and all of its elements
must be registered in the Alias Map
.serialize
in interface Serializer
serialize
in interface TextSerializer
obj
- the object to be serialized.generator
- the writer that holds the serialized object.JSONSerializerException
public java.lang.String serialize(java.lang.String semanticType, java.lang.Object obj) throws SerializerException
TextSerializer
Java Object
into string. The object may be
a plain Java object or an instance of a StructuredDataObject
.
The object must be defined as a known Semantic Type and all of its elements must be registered
in the Alias Map
.
This method allows for a specific semantic type to be specified, which results in a form of protected casting for
the object based on the Alias Map
. It is therefore possible to serialize varied objects that implement
the same interface.
serialize
in interface TextSerializer
semanticType
- the semantic type of the specified object.obj
- the object to be serializedSerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public void serialize(java.lang.String semanticType, java.lang.Object obj, java.io.Writer writer) throws SerializerException
TextSerializer
Writer
. The object may be an
instance of StructuredDataObject
or a standard Java object. The actual output format is
implementation specific. The object must be defined as a known Semantic Type and all of its elements
must be registered in the Alias Map
.
This method allows for a specific semantic type to be specified, which results in a form of protected casting for
the object based on the Alias Map
. It is therefore possible to serialize varied objects that implement
the same interface.
serialize
in interface TextSerializer
semanticType
- the semantic type of the specified object.obj
- the object to be serialized.writer
- the writer that holds the serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public void serialize(java.lang.String semanticType, java.lang.Object obj, java.io.DataOutputStream stream) throws SerializerException
Serializer
DataOutputStream
. The object may be an
instance of StructuredDataObject
or a standard Java object. The actual stream format is
implementation specific. The object must be defined as a known Semantic Type and all of its elements
must be registered in the Alias Map
.
This method allows for a specific semantic type to be specified, which results in a form of protected casting for
the object based on the Alias Map
. It is therefore possible to serialize varied objects that implement
the same interface.
serialize
in interface Serializer
semanticType
- the semantic type of the specified object.obj
- the object to be serialized.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public java.lang.Object deserialize(java.lang.String buffer) throws SerializerException
TextSerializer
Alias Map
.
The actual instance creation is implementation specific. Framework serializers may not require the presence of a
null constructor.deserialize
in interface TextSerializer
buffer
- the string containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public java.lang.Object deserialize(java.io.Reader reader) throws SerializerException
TextSerializer
Reader
. The reader is a text representation of an
object in its serialized form. Meaning that the actual format of the object may be XML or JSON or whatever
format dictated by the serializer. The actual format is implementation specific. This method requires that the
object must be defined as a known Semantic Type and all of its elements must be registered in the Alias Map
.
The actual instance creation is implementation specific and may depend on the specific JVM. Framework serializers may
not require the presence of a null constructor.deserialize
in interface TextSerializer
reader
- the reader containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public java.lang.Object deserialize(byte[] buffer) throws SerializerException
Serializer
Alias Map
.
The actual instance creation is implementation specific. Framework serializers may not require the presence of a
null constructor.deserialize
in interface Serializer
buffer
- the buffer containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public java.lang.Object deserialize(java.io.DataInputStream stream) throws SerializerException
Serializer
DataOutputStream
. The stream is a byte representation of an
object in its serialized form. Meaning that the actual format of the object may be binary or text or XML or whatever
format dictated by the serializer. The actual binary format is implementation specific. This method requires that the
object must be defined as a known Semantic Type and all of its elements must be registered in the Alias Map
.
The actual instance creation is implementation specific and may depend on the specific JVM. Framework serializers may
not require the presence of a null constructor.deserialize
in interface Serializer
stream
- the stream containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public java.lang.Object deserialize(JsonParser parser) throws SerializerException
TextSerializer
Alias Map
.
The actual instance creation is implementation specific. Framework serializers may not require the presence of a
null constructor.deserialize
in interface Serializer
deserialize
in interface TextSerializer
parser
- the string containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public java.lang.Object deserialize(java.lang.String semanticType, java.lang.String buffer) throws SerializerException
TextSerializer
Alias Map
. The actual instance
creation is implementation specific and may be JVM dependent. Framework serializers may not require the presence of a
null constructor.
The method allows users to specify a particular semantic type, thereby engaging in forced casting of the deserialized object.
deserialize
in interface TextSerializer
semanticType
- the semantic type of the specified object.buffer
- the string containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public java.lang.Object deserialize(java.lang.String semanticType, java.io.Reader reader) throws SerializerException
TextSerializer
Reader
. The reader is a text representation of an
object in its serialized form. Meaning that the actual format of the object may be XML or JSON or whatever
format dictated by the serializer. The actual format is implementation specific. This method requires that the
supplied Semantic Type and all of its elements must be registered in the Alias Map
. The actual
instance creation is implementation specific and may depend on the specific JVM. Framework serializers may not require
the presence of a null constructor.
The method allows users to specify a particular semantic type, thereby engaging in forced casting of the deserialized object.
deserialize
in interface TextSerializer
semanticType
- the semantic type of the specified object.reader
- the reader containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public java.lang.Object deserialize(java.lang.String semanticType, byte[] buffer) throws SerializerException
Serializer
Alias Map
. The actual instance
creation is implementation specific and may be JVM dependent. Framework serializers may not require the presence of a
null constructor.
The method allows users to specify a particular semantic type, thereby engaging in forced casting of the deserialized object.
deserialize
in interface Serializer
semanticType
- the semantic type of the specified object.buffer
- the buffer containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public java.lang.Object deserialize(java.lang.String semanticType, java.io.DataInputStream stream) throws SerializerException
Serializer
DataOutputStream
. The stream is a byte representation of an
object in its serialized form. Meaning that the actual format of the object may be binary or text or XML or whatever
format dictated by the serializer. The actual binary format is implementation specific. This method requires that the
supplied Semantic Type and all of its elements must be registered in the Alias Map
. The actual
instance creation is implementation specific and may depend on the specific JVM. Framework serializers may not require
the presence of a null constructor.
The method allows users to specify a particular semantic type, thereby engaging in forced casting of the deserialized object.
deserialize
in interface Serializer
semanticType
- the semantic type of the specified object.stream
- the buffer containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public java.lang.Object deserialize(java.lang.String semanticType, JsonParser parser) throws SerializerException
TextSerializer
Alias Map
. The actual instance
creation is implementation specific and may be JVM dependent. Framework serializers may not require the presence of a
null constructor.
The method allows users to specify a particular semantic type, thereby engaging in forced casting of the deserialized object.
deserialize
in interface Serializer
deserialize
in interface TextSerializer
semanticType
- the semantic type of the specified object.parser
- the string containing serialized object.SerializerException
- if an object type or class are not defined in the Alias Map
or
if other errors occur.public java.lang.Object deserialize(java.lang.Class objectClass, JsonParser parser) throws SerializerException
TextSerializer
buffer
. Buffer contains a text representation of an
object in its serialized form. Meaning that the actual format of the object may be XML or JSON or whatever
format dictated by the serializer. The actual format is implementation specific.
The method allows users to specify a particular semantic type, thereby engaging in forced casting of the deserialized object.
deserialize
in interface TextSerializer
objectClass
- the class of the specified object.parser
- the buffer containing serialized object.SerializerException
- if some errors occur.public JsonParser createParser(java.lang.String content) throws java.io.IOException
java.io.IOException
public JsonParser createParser(byte[] content) throws java.io.IOException
java.io.IOException
public JsonGenerator createGenerator(java.io.OutputStream output, JsonEncoding encoding) throws java.io.IOException
java.io.IOException
public JsonGenerator createGenerator(java.io.OutputStream output, JsonEncoding encoding, boolean useSamePrettyPrinter) throws java.io.IOException
java.io.IOException
public java.lang.Class resolveSemanticClass(java.lang.String semanticType) throws SerializerException
SerializerException
public static boolean isUnquotedString(java.lang.String buffer)
public static JSONSerializer.JsonSerializerBuilderImpl builder()
public static JSONSerializer.JsonSerializerBuilderImpl builder(JSONSerializer template)
public void failOnUnknownElements(boolean flag)
public static JSONSerializer getContextJsonSerializer()
Copyright © 2015-2024 StreamScape Technologies. All rights reserved.