Package com.helger.jaxb
Interface IJAXBWriter<JAXBTYPE>
- Type Parameters:
JAXBTYPE- The JAXB type to be written
- All Known Implementing Classes:
GenericJAXBMarshaller,JAXBWriterBuilder
public interface IJAXBWriter<JAXBTYPE>
Interface for writing JAXB documents to various destinations.
- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanUse theSafeXMLStreamWriterwhere applicable to ensure valid XML is created? -
Method Summary
Modifier and TypeMethodDescriptiondefault ByteBuffergetAsByteBuffer(JAXBTYPE aObject) Write the passed object to aByteBufferand return it (write).default byte[]getAsBytes(JAXBTYPE aObject) Write the passed object to a byte array and return the created byte array (write).default DocumentgetAsDocument(JAXBTYPE aObject) Convert the passed object to a new DOM document (write).default ElementgetAsElement(JAXBTYPE aObject) Convert the passed object to a new DOM document and return the document element (write).default com.helger.commons.io.stream.NonBlockingByteArrayInputStreamgetAsInputStream(JAXBTYPE aObject) Write the passed object to a byte array and return the input stream on that array.default com.helger.xml.microdom.IMicroDocumentgetAsMicroDocument(JAXBTYPE aObject) Convert the passed object to a new micro document (write).default com.helger.xml.microdom.IMicroElementgetAsMicroElement(JAXBTYPE aObject) Convert the passed object to a new micro document and return only the root element (write).default StringgetAsString(JAXBTYPE aObject) Utility method to directly convert the passed domain object to an XML string (write).default com.helger.xml.serialize.write.IXMLWriterSettingsdefault booleandefault booleandefault booleandefault booleanbooleanbooleandefault com.helger.commons.state.ESuccessWrite the passed object to anIWritableResource.com.helger.commons.state.ESuccesswrite(JAXBTYPE aObject, IJAXBMarshaller<JAXBTYPE> aMarshallerFunc) Convert the passed object to XML.default com.helger.commons.state.ESuccessWrite the passed object to aFile.default com.helger.commons.state.ESuccesswrite(JAXBTYPE aObject, OutputStream aOS) Write the passed object to anOutputStream.default com.helger.commons.state.ESuccessWrite the passed object to aWriter.default com.helger.commons.state.ESuccesswrite(JAXBTYPE aObject, ByteBuffer aBuffer) Write the passed object to aByteBuffer.default com.helger.commons.state.ESuccessWrite the passed object to aPath.default com.helger.commons.state.ESuccesswrite(JAXBTYPE aObject, XMLStreamWriter aWriter) Convert the passed object to XML.default com.helger.commons.state.ESuccessConvert the passed object to XML.default com.helger.commons.state.ESuccesswrite(JAXBTYPE aObject, ContentHandler aHandler) Convert the passed object to XML.
-
Field Details
-
USE_JAXB_CHARSET_FIX
static final boolean USE_JAXB_CHARSET_FIXUse theSafeXMLStreamWriterwhere applicable to ensure valid XML is created? This is a work around for https://github.com/eclipse-ee4j/jaxb-ri/issues/614 and https://github.com/eclipse-ee4j/jaxb-ri/issues/960
Note: these bugs are still open for JAXB 4.0.0- See Also:
-
-
Method Details
-
getNamespaceContext
- Returns:
- The special JAXB namespace context to be used. May be
null. - Since:
- 8.5.3 in this interface
-
isFormattedOutput
boolean isFormattedOutput()- Returns:
trueif the JAXB output should be formatted. Default isfalse.- Since:
- 8.5.3 in this interface
-
getCharset
- Returns:
- The special JAXB Charset to be used for writing.
nullby default. - Since:
- 8.5.3 in this interface
-
hasCharset
default boolean hasCharset() -
getIndentString
- Returns:
- The JAXB indentation string to be used for writing.
nullby default. Only used when formatted output is used. - Since:
- 8.5.3 in this interface
-
hasIndentString
default boolean hasIndentString() -
isUseSchema
boolean isUseSchema()- Returns:
trueif an eventually configured XML Schema should be used,falseto explicitly disable the usage of XML Schema.- Since:
- 11.0.3
-
getSchemaLocation
- Returns:
- The schema location to be used for writing.
nullby default. - Since:
- 8.6.0
-
hasSchemaLocation
default boolean hasSchemaLocation() -
getNoNamespaceSchemaLocation
- Returns:
- The no namespace schema location to be used for writing.
nullby default. - Since:
- 9.0.0
-
hasNoNamespaceSchemaLocation
default boolean hasNoNamespaceSchemaLocation() -
getXMLWriterSettings
- Returns:
- The XML writer settings to be used based on this writer settings.
Never
null.
-
write
@Nonnull default com.helger.commons.state.ESuccess write(@Nonnull JAXBTYPE aObject, @Nonnull File aResultFile) Write the passed object to aFile.- Parameters:
aObject- The object to be written. May not benull.aResultFile- The result file to be written to. May not benull.- Returns:
ESuccess
-
write
@Nonnull default com.helger.commons.state.ESuccess write(@Nonnull JAXBTYPE aObject, @Nonnull Path aResultPath) Write the passed object to aPath.- Parameters:
aObject- The object to be written. May not benull.aResultPath- The result path to be written to. May not benull.- Returns:
ESuccess
-
write
@Nonnull default com.helger.commons.state.ESuccess write(@Nonnull JAXBTYPE aObject, @Nonnull @WillClose OutputStream aOS) Write the passed object to anOutputStream.- Parameters:
aObject- The object to be written. May not benull.aOS- The output stream to write to. Will always be closed. May not benull.- Returns:
ESuccess
-
write
@Nonnull default com.helger.commons.state.ESuccess write(@Nonnull JAXBTYPE aObject, @Nonnull @WillClose Writer aWriter) Write the passed object to aWriter.- Parameters:
aObject- The object to be written. May not benull.aWriter- The writer to write to. Will always be closed. May not benull.- Returns:
ESuccess
-
write
@Nonnull default com.helger.commons.state.ESuccess write(@Nonnull JAXBTYPE aObject, @Nonnull ByteBuffer aBuffer) Write the passed object to aByteBuffer.- Parameters:
aObject- The object to be written. May not benull.aBuffer- The byte buffer to write to. If the buffer is too small, it is automatically extended. May not benull.- Returns:
ESuccess- Throws:
BufferOverflowException- If the ByteBuffer is too small
-
write
@Nonnull default com.helger.commons.state.ESuccess write(@Nonnull JAXBTYPE aObject, @Nonnull com.helger.commons.io.resource.IWritableResource aResource) Write the passed object to anIWritableResource.- Parameters:
aObject- The object to be written. May not benull.aResource- The result resource to be written to. May not benull.- Returns:
ESuccess
-
write
@Nonnull com.helger.commons.state.ESuccess write(@Nonnull JAXBTYPE aObject, @Nonnull IJAXBMarshaller<JAXBTYPE> aMarshallerFunc) Convert the passed object to XML.- Parameters:
aObject- The object to be converted. May not benull.aMarshallerFunc- The marshalling function. May not benull.- Returns:
ESuccess
-
write
@Nonnull default com.helger.commons.state.ESuccess write(@Nonnull JAXBTYPE aObject, @Nonnull Result aResult) Convert the passed object to XML. This method is potentially dangerous, when using StreamResult because it may create invalid XML. Only when using theSafeXMLStreamWriterit is ensured that only valid XML is created!- Parameters:
aObject- The object to be converted. May not benull.aResult- The result object holder. May not benull. Usually SAXResult, DOMResult and StreamResult are supported.- Returns:
ESuccess
-
write
@Nonnull default com.helger.commons.state.ESuccess write(@Nonnull JAXBTYPE aObject, @Nonnull ContentHandler aHandler) Convert the passed object to XML.- Parameters:
aObject- The object to be converted. May not benull.aHandler- XML will be sent to this handler as SAX2 events. May not benull.- Returns:
ESuccess
-
write
@Nonnull default com.helger.commons.state.ESuccess write(@Nonnull JAXBTYPE aObject, @Nonnull @WillClose XMLStreamWriter aWriter) Convert the passed object to XML.- Parameters:
aObject- The object to be converted. May not benull.aWriter- XML will be sent to this writer. May not benull.- Returns:
ESuccess
-
getAsDocument
Convert the passed object to a new DOM document (write).- Parameters:
aObject- The object to be converted. May not benull.- Returns:
nullif converting the document failed.
-
getAsElement
Convert the passed object to a new DOM document and return the document element (write).- Parameters:
aObject- The object to be converted. May not benull.- Returns:
nullif converting the document failed.- Since:
- 11.0.2
-
getAsMicroDocument
@Nullable default com.helger.xml.microdom.IMicroDocument getAsMicroDocument(@Nonnull JAXBTYPE aObject) Convert the passed object to a new micro document (write).- Parameters:
aObject- The object to be converted. May not benull.- Returns:
nullif converting the document failed.
-
getAsMicroElement
@Nullable default com.helger.xml.microdom.IMicroElement getAsMicroElement(@Nonnull JAXBTYPE aObject) Convert the passed object to a new micro document and return only the root element (write).- Parameters:
aObject- The object to be converted. May not benull.- Returns:
nullif converting the document failed.
-
getAsString
Utility method to directly convert the passed domain object to an XML string (write).- Parameters:
aObject- The domain object to be converted. May not benull.- Returns:
nullif the passed domain object could not be converted because of validation errors.
-
getAsByteBuffer
Write the passed object to aByteBufferand return it (write).- Parameters:
aObject- The object to be written. May not benull.- Returns:
nullif the passed domain object could not be converted because of validation errors.
-
getAsBytes
Write the passed object to a byte array and return the created byte array (write).- Parameters:
aObject- The object to be written. May not benull.- Returns:
nullif the passed domain object could not be converted because of validation errors.
-
getAsInputStream
@Nullable default com.helger.commons.io.stream.NonBlockingByteArrayInputStream getAsInputStream(@Nonnull JAXBTYPE aObject) Write the passed object to a byte array and return the input stream on that array.- Parameters:
aObject- The object to be written. May not benull.- Returns:
nullif the passed domain object could not be converted because of validation errors.- Since:
- 9.1.8
-