public class JodaBeanJsonWriter
extends java.lang.Object
This class contains mutable state and cannot be used from multiple threads. A new instance must be created for each message.
The JSON format is kept relatively natural, however some meta-data is added. This has the unfortunate effect of adding an additional object structure to hold the type in a few places.
Beans are output using JSON objects where the key is the property name. The type of the bean will be sent using the '@type' property name if necessary.
Most simple types, defined by Joda-Convert, are output as JSON strings. If the simple type requires additional type information, the value is replaced by a JSON object containing the keys '@type' and 'value'.
Null values are generally omitted, but where included are sent as 'null'. Boolean values are sent as 'true' and 'false'. Integer and Double values are sent as JSON numbers. Other numeric types are also sent as numbers but may have additional type information.
Collections are output using JSON objects or arrays. Multisets are output as a map of value to count.
If a collection contains a collection then addition meta-type information is written to aid with deserialization. At this level, the data read back may not be identical to that written. If the collection type requires additional type information, the value is replaced by a JSON object containing the keys '@meta' and 'value'.
Type names are shortened by the package of the root type if possible. Certain basic types are also handled, such as String, Integer, File and URI.
| Constructor | Description |
|---|---|
JodaBeanJsonWriter(JodaBeanSer settings) |
Creates an instance.
|
| Modifier and Type | Method | Description |
|---|---|---|
java.lang.String |
write(Bean bean) |
Writes the bean to a string.
|
java.lang.String |
write(Bean bean,
boolean rootType) |
Writes the bean to a string specifying whether to include the type at the root.
|
void |
write(Bean bean,
boolean rootType,
java.lang.Appendable output) |
Writes the bean to the
Appendable specifying whether to include the type at the root. |
void |
write(Bean bean,
java.lang.Appendable output) |
Writes the bean to the
Appendable. |
public JodaBeanJsonWriter(JodaBeanSer settings)
settings - the settings to use, not nullpublic java.lang.String write(Bean bean)
The type of the bean will be set in the message.
bean - the bean to output, not nullpublic java.lang.String write(Bean bean, boolean rootType)
bean - the bean to output, not nullrootType - true to output the root typepublic void write(Bean bean, java.lang.Appendable output) throws java.io.IOException
Appendable.
The type of the bean will be set in the message.
bean - the bean to output, not nulloutput - the output appendable, not nulljava.io.IOException - if an error occurspublic void write(Bean bean, boolean rootType, java.lang.Appendable output) throws java.io.IOException
Appendable specifying whether to include the type at the root.bean - the bean to output, not nullrootType - true to output the root typeoutput - the output appendable, not nulljava.io.IOException - if an error occursCopyright © 2007–2018 Joda.org. All rights reserved.