public class JSONConverter extends Converter<java.lang.String>
Representation object and a JSON structure.
The output is not optimized for legibility, i.e. no whitespaces.
For creating pretty-printed JSON output, see JSONPrettyConverter.
Note that the order of attributes in a JSON Object is meaningless.
However, this Converter guarantees a consistent order between calls,
making the Representation -> String relation left-unique (i.e. a well-defined mapping).
This allows this Converter to be used for, e.g,. HashRepresentationIntoStructure,
and similar tasks that require a unique and consistent output.
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.String |
BIG_INTEGER_PREFIX |
protected static java.lang.String |
BYTE_ARRAY_PREFIX |
protected static java.lang.String |
MAP_OBJ_TYPE |
protected static java.lang.String |
OBJ_OBJ_TYPE |
protected static java.lang.String |
OBJ_TYPE_KEY |
protected static java.lang.String |
REPR_OBJ_TYPE |
protected static java.lang.String |
STRING_PREFIX |
| Constructor and Description |
|---|
JSONConverter() |
| Modifier and Type | Method and Description |
|---|---|
Representation |
deserialize(java.lang.String s)
Deserializes the given object to its representation.
|
protected Representation |
internalDeserialize(java.lang.Object o)
Deserializes the given object (constructed via conversion from JSON) to its representation.
|
protected java.lang.Object |
internalSerialize(Representation r)
Serializes the given representation to an
Object that can be easily converted to JSON. |
java.lang.String |
serialize(Representation r)
Serializes the given representation to the type supported by this converter.
|
protected static final java.lang.String BIG_INTEGER_PREFIX
protected static final java.lang.String BYTE_ARRAY_PREFIX
protected static final java.lang.String STRING_PREFIX
protected static final java.lang.String OBJ_TYPE_KEY
protected static final java.lang.String MAP_OBJ_TYPE
protected static final java.lang.String REPR_OBJ_TYPE
protected static final java.lang.String OBJ_OBJ_TYPE
public java.lang.String serialize(Representation r)
Converterprotected java.lang.Object internalSerialize(Representation r)
Object that can be easily converted to JSON.r - the representation to serializepublic Representation deserialize(java.lang.String s)
Converterdeserialize in class Converter<java.lang.String>s - the object to deserializeprotected Representation internalDeserialize(java.lang.Object o)
o - the object to deserialize to representation