Class JodaBeanSer
- java.lang.Object
-
- org.joda.beans.ser.JodaBeanSer
-
public final class JodaBeanSer extends Object
Provides the ability for a Joda-Bean to be serialized.Serialization of Joda-Beans uses the information in the beans to optimize the size of the data output.
-
-
Field Summary
Fields Modifier and Type Field Description static JodaBeanSer
COMPACT
Obtains the singleton compact instance.static JodaBeanSer
PRETTY
Obtains the singleton pretty-printing instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JodaBeanBinReader
binReader()
Creates a binary reader that handles both the standard and referencing binary formats.JodaBeanBinWriter
binWriter()
Creates a binary writer using the standard format.JodaBeanBinWriter
binWriterReferencing()
Creates a binary writer using the referencing format that typically results in a smaller output.org.joda.convert.StringConvert
getConverter()
Gets the string converter.SerDeserializers
getDeserializers()
Gets the deserializers.String
getIndent()
Gets the pretty print indent.SerIteratorFactory
getIteratorFactory()
Gets the iterator factory.String
getNewLine()
Gets the new line string.boolean
isIncludeDerived()
Gets the include derived flag.boolean
isSerialized(MetaProperty<?> prop)
Checks if the property is serialized.boolean
isShortTypes()
Gets whether to use short types.JodaBeanJsonReader
jsonReader()
Creates a JSON reader.JodaBeanJsonWriter
jsonWriter()
Creates a JSON writer.JodaBeanSimpleJsonReader
simpleJsonReader()
Creates a simple JSON reader.JodaBeanSimpleJsonWriter
simpleJsonWriter()
Creates a simple JSON writer.JodaBeanSimpleMapReader
simpleMapReader()
Creates a simple in-memoryMap
reader.JodaBeanSimpleMapWriter
simpleMapWriter()
Creates a simple in-memoryMap
writer.JodaBeanSmartReader
smartReader()
Creates a reader that determines the file format and parses it.String
toString()
JodaBeanSer
withConverter(org.joda.convert.StringConvert converter)
Returns a copy of this serializer with the specified string converter.JodaBeanSer
withDeserializers(SerDeserializers deserializers)
Returns a copy of this serializer with the specified deserializers.JodaBeanSer
withIncludeDerived(boolean includeDerived)
Returns a copy of this serializer with the specified include derived flag.JodaBeanSer
withIndent(String indent)
Returns a copy of this serializer with the specified pretty print indent.JodaBeanSer
withIteratorFactory(SerIteratorFactory iteratorFactory)
Returns a copy of this serializer with the specified iterator factory.JodaBeanSer
withNewLine(String newLine)
Returns a copy of this serializer with the specified pretty print new line.JodaBeanSer
withShortTypes(boolean shortTypes)
Returns a copy of this serializer with the short types flag set.JodaBeanXmlReader
xmlReader()
Creates an XML reader.JodaBeanXmlWriter
xmlWriter()
Creates an XML writer.
-
-
-
Field Detail
-
COMPACT
public static final JodaBeanSer COMPACT
Obtains the singleton compact instance.
-
PRETTY
public static final JodaBeanSer PRETTY
Obtains the singleton pretty-printing instance.
-
-
Method Detail
-
getIndent
public String getIndent()
Gets the pretty print indent.- Returns:
- the indent, not null
-
withIndent
public JodaBeanSer withIndent(String indent)
Returns a copy of this serializer with the specified pretty print indent.- Parameters:
indent
- the indent, not null- Returns:
- a copy of this object with the indent changed, not null
-
getNewLine
public String getNewLine()
Gets the new line string.- Returns:
- the newLine, not null
-
withNewLine
public JodaBeanSer withNewLine(String newLine)
Returns a copy of this serializer with the specified pretty print new line.- Parameters:
newLine
- the new line, not null- Returns:
- a copy of this object with the new line changed, not null
-
getConverter
public org.joda.convert.StringConvert getConverter()
Gets the string converter.The default converter can be modified.
- Returns:
- the converter, not null
-
withConverter
public JodaBeanSer withConverter(org.joda.convert.StringConvert converter)
Returns a copy of this serializer with the specified string converter.The default converter can be modified.
- Parameters:
converter
- the converter, not null- Returns:
- a copy of this object with the converter changed, not null
-
getIteratorFactory
public SerIteratorFactory getIteratorFactory()
Gets the iterator factory.- Returns:
- the iterator factory, not null
-
withIteratorFactory
public JodaBeanSer withIteratorFactory(SerIteratorFactory iteratorFactory)
Returns a copy of this serializer with the specified iterator factory.- Parameters:
iteratorFactory
- the iterator factory, not null- Returns:
- a copy of this object with the iterator factory changed, not null
-
isShortTypes
public boolean isShortTypes()
Gets whether to use short types.- Returns:
- the short types flag, not null
-
withShortTypes
public JodaBeanSer withShortTypes(boolean shortTypes)
Returns a copy of this serializer with the short types flag set.- Parameters:
shortTypes
- whether to use short types, not null- Returns:
- a copy of this object with the short types flag changed, not null
-
getDeserializers
public SerDeserializers getDeserializers()
Gets the deserializers.The default deserializers can be modified.
- Returns:
- the converter, not null
-
withDeserializers
public JodaBeanSer withDeserializers(SerDeserializers deserializers)
Returns a copy of this serializer with the specified deserializers.The default deserializers can be modified.
This can be used to select a more lenient mode of parsing, see
SerDeserializers.LENIENT
.- Parameters:
deserializers
- the deserializers, not null- Returns:
- a copy of this object with the converter changed, not null
-
isIncludeDerived
public boolean isIncludeDerived()
Gets the include derived flag.The default deserializers can be modified.
- Returns:
- the converter, not null
-
withIncludeDerived
public JodaBeanSer withIncludeDerived(boolean includeDerived)
Returns a copy of this serializer with the specified include derived flag.The default deserializers can be modified.
This is used to set the output to include derived properties.
- Parameters:
includeDerived
- whether to include derived properties on output- Returns:
- a copy of this object with the converter changed, not null
-
isSerialized
public boolean isSerialized(MetaProperty<?> prop)
Checks if the property is serialized.- Parameters:
prop
- the property to check- Returns:
- true if the property is seialized
-
smartReader
public JodaBeanSmartReader smartReader()
Creates a reader that determines the file format and parses it.This parser can handle XML, JSON, simple JSON, binary and binary referencing formats.
It is recommended, though not necessary, to create a new instance of the reader for each message.
- Returns:
- the smart reader, not null
-
binWriter
public JodaBeanBinWriter binWriter()
Creates a binary writer using the standard format.It is recommended, though not necessary, to create a new instance of the writer for each message.
- Returns:
- the binary writer, not null
-
binWriterReferencing
public JodaBeanBinWriter binWriterReferencing()
Creates a binary writer using the referencing format that typically results in a smaller output.It is recommended, though not necessary, to create a new instance of the writer for each message.
The writer only supports serializing ImmutableBean instances and will throw an exception if any non-immutable beans are encountered. It assumes that non-bean items present within the root bean are themselves immutable. Due to this immutability restriction it serializes references to values based on object equality, rather than based on reference equality. When the output is parsed it may be smaller in memory as any beans that were originally equal will be returned as pointers to the same instance.
The reader
binReader()
handles both the standard and referencing formats.- Returns:
- the referencing binary writer, not null
-
binReader
public JodaBeanBinReader binReader()
Creates a binary reader that handles both the standard and referencing binary formats.It is recommended, though not necessary, to create a new instance of the reader for each message.
- Returns:
- the binary reader, not null
-
xmlWriter
public JodaBeanXmlWriter xmlWriter()
Creates an XML writer.A new instance of the writer must be created for each message.
- Returns:
- the XML writer, not null
-
xmlReader
public JodaBeanXmlReader xmlReader()
Creates an XML reader.A new instance of the reader must be created for each message.
- Returns:
- the XML reader, not null
-
jsonWriter
public JodaBeanJsonWriter jsonWriter()
Creates a JSON writer.A new instance of the writer must be created for each message.
- Returns:
- the JSON writer, not null
-
jsonReader
public JodaBeanJsonReader jsonReader()
Creates a JSON reader.A new instance of the reader must be created for each message.
- Returns:
- the JSON reader, not null
-
simpleJsonWriter
public JodaBeanSimpleJsonWriter simpleJsonWriter()
Creates a simple JSON writer.A new instance of the writer must be created for each message. The simple writer omits all metadata. It is suitable for simple beans as often found in data-transfer protocols.
Not all beans can be used with the simple JSON writer as no type information is written. If a bean has subclasses, or the declared type of a property or collection is
Object
, then the JSON will not round trip. Where the type cannot be determined, the reader will returnBoolean
,Integer
,Double
,String
,ArrayList
or string keyedHashMap
. Maps must have keys that can be written as a string.- Returns:
- the simple JSON writer, not null
-
simpleJsonReader
public JodaBeanSimpleJsonReader simpleJsonReader()
Creates a simple JSON reader.A new instance of the reader must be created for each message. The simple reader is designed to operate with the simple writer. It will not operate well with the output of
jsonWriter()
.- Returns:
- the simple JSON reader, not null
-
simpleMapWriter
public JodaBeanSimpleMapWriter simpleMapWriter()
Creates a simple in-memoryMap
writer.A new instance of the writer must be created for each message.
- Returns:
- the simple map writer, not null
-
simpleMapReader
public JodaBeanSimpleMapReader simpleMapReader()
Creates a simple in-memoryMap
reader.A new instance of the reader must be created for each message.
- Returns:
- the simple map reader, not null
-
-