Interface Marshaller
-
- All Superinterfaces:
Debuggable
- All Known Implementing Classes:
MarshallerImpl
public interface Marshaller extends Debuggable
Interface for marshalling bean objects.A
Marshallercan be used to marshal a bean object bound to arecordin 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
Stringvalue, as shown in the following example:marshaller.marshal(object).toString();
A
Marshallerinstance is stateful. If a BeanIO mapping file declares record ordering and expected occurrences, aBeanWriterExceptionmay 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
Marshallerinstance, but aMarshalleris 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 Marshallermarshal(java.lang.Object bean)Marshals a single bean object.Marshallermarshal(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[]forcsvanddelimitedformatted streams.org.w3c.dom.DocumenttoDocument()Returns the most recent marshalled bean object as aDocumentforxmlformatted streams.java.util.List<java.lang.String>toList()Returns the most recent marshalled bean object as aListforcsvanddelimitedformatted streams.java.lang.StringtoString()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 BeanWriterExceptionReturns the most recent marshalled bean object as aString. This method is supported by all stream formats.- Overrides:
toStringin classjava.lang.Object- Returns:
- the record text
- Throws:
BeanWriterException- if a fatal error occurs
-
toArray
java.lang.String[] toArray() throws BeanWriterExceptionReturns the most recent marshalled bean object as aString[]forcsvanddelimitedformatted streams.- Returns:
- the
Stringarray of fields - Throws:
BeanWriterException- if an array is not supported by the stream format
-
toList
java.util.List<java.lang.String> toList() throws BeanWriterExceptionReturns the most recent marshalled bean object as aListforcsvanddelimitedformatted streams.- Returns:
- the
Listof fields - Throws:
BeanWriterException- if an array is not supported by the stream format
-
toDocument
org.w3c.dom.Document toDocument() throws BeanWriterExceptionReturns the most recent marshalled bean object as aDocumentforxmlformatted streams.- Returns:
- the
Document - Throws:
BeanWriterException- ifDocumentis not supported by the stream format
-
-