Interface Marshaller
-
- All Superinterfaces:
Debuggable
- All Known Implementing Classes:
MarshallerImpl
public interface Marshaller extends Debuggable
Interface for marshalling bean objects.A
Marshaller
can be used to marshal a bean object bound to arecord
in a mapping file. Marshalling bean objects that span multiple records is not supported and will cause aBeanWriterException
.Depending on the stream format, a bean object can be marshalled to one or more formats. All stream formats support marshalling to a
String
value, as shown in the following example:marshaller.marshal(object).toString();
A
Marshaller
instance is stateful. If a BeanIO mapping file declares record ordering and expected occurrences, aBeanWriterException
may be thrown for bean objects written out of sequence or that have exceeded a record's maximum occurrences.There is some performance benefit for reusing the same
Marshaller
instance, but aMarshaller
is not thread safe and should not be used to concurrently marshal multiple bean objects.- Since:
- 2.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Marshaller
marshal(java.lang.Object bean)
Marshals a single bean object.Marshaller
marshal(java.lang.String recordName, java.lang.Object bean)
Marshals a single bean object.java.lang.String[]
toArray()
Returns the most recent marshalled bean object as aString[]
forcsv
anddelimited
formatted streams.org.w3c.dom.Document
toDocument()
Returns the most recent marshalled bean object as aDocument
forxml
formatted streams.java.util.List<java.lang.String>
toList()
Returns the most recent marshalled bean object as aList
forcsv
anddelimited
formatted streams.java.lang.String
toString()
Returns the most recent marshalled bean object as aString
.-
Methods inherited from interface org.beanio.internal.util.Debuggable
debug, debug
-
-
-
-
Method Detail
-
marshal
Marshaller marshal(java.lang.Object bean) throws BeanWriterException
Marshals a single bean object.- Parameters:
bean
- the bean object to marshal- Returns:
- this
Marshaller
- Throws:
BeanWriterException
- if a record is not matched for the given bean object, or in some other rare (but fatal) conditionsInvalidBeanException
- if BeanIO is configured to validate fields during marshalling, and a field does not meet the configured validation rules
-
marshal
Marshaller marshal(java.lang.String recordName, java.lang.Object bean) throws BeanWriterException
Marshals a single bean object.- Parameters:
recordName
- the name of the record to marshalbean
- the bean object to marshal- Returns:
- this
Marshaller
- Throws:
BeanWriterException
- if a record is not matched for the given record name and bean object, or in some other rare (but fatal) conditionsInvalidBeanException
- if BeanIO is configured to validate fields during marshalling, and a field does not meet the configured validation rules
-
toString
java.lang.String toString() throws BeanWriterException
Returns the most recent marshalled bean object as aString
. This method is supported by all stream formats.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the record text
- Throws:
BeanWriterException
- if a fatal error occurs
-
toArray
java.lang.String[] toArray() throws BeanWriterException
Returns the most recent marshalled bean object as aString[]
forcsv
anddelimited
formatted streams.- Returns:
- the
String
array of fields - Throws:
BeanWriterException
- if an array is not supported by the stream format
-
toList
java.util.List<java.lang.String> toList() throws BeanWriterException
Returns the most recent marshalled bean object as aList
forcsv
anddelimited
formatted streams.- Returns:
- the
List
of fields - Throws:
BeanWriterException
- if an array is not supported by the stream format
-
toDocument
org.w3c.dom.Document toDocument() throws BeanWriterException
Returns the most recent marshalled bean object as aDocument
forxml
formatted streams.- Returns:
- the
Document
- Throws:
BeanWriterException
- ifDocument
is not supported by the stream format
-
-