Class MetaschemaXmlWriter

java.lang.Object
dev.metaschema.databind.io.xml.MetaschemaXmlWriter
All Implemented Interfaces:
IWritingContext<org.codehaus.stax2.XMLStreamWriter2>, IXmlWritingContext

public class MetaschemaXmlWriter extends Object implements IXmlWritingContext
Provides support for writing Metaschema-bound Java objects to XML format.

This class implements the IXmlWritingContext interface to serialize bound objects to XML using StAX's XMLStreamWriter2. It handles flags as attributes and fields/assemblies as child elements according to the Metaschema XML serialization rules.

See Also:
  • Constructor Details

    • MetaschemaXmlWriter

      public MetaschemaXmlWriter(@NonNull org.codehaus.stax2.XMLStreamWriter2 writer)
      Construct a new Module-aware JSON writer.
      Parameters:
      writer - the XML stream writer to write with
      See Also:
  • Method Details

    • getWriter

      public org.codehaus.stax2.XMLStreamWriter2 getWriter()
      Description copied from interface: IWritingContext
      Get the writer associated with the writing context.
      Specified by:
      getWriter in interface IWritingContext<org.codehaus.stax2.XMLStreamWriter2>
      Returns:
      the writer
    • write

      public void write(@NonNull IBoundDefinitionModelComplex definition, @NonNull IBoundObject item) throws IOException
      Description copied from interface: IWritingContext
      Write the data described by the provided targetObject as an XML element.
      Specified by:
      write in interface IWritingContext<org.codehaus.stax2.XMLStreamWriter2>
      Parameters:
      definition - the bound Module definition describing the data to write
      item - the Java object data to write
      Throws:
      IOException - if an error occurred while writing
    • writeRoot

      public void writeRoot(@NonNull IBoundDefinitionModelAssembly definition, @NonNull IBoundObject item) throws IOException
      Description copied from interface: IXmlWritingContext
      Write the root element for the provided definition and bound object.
      Specified by:
      writeRoot in interface IXmlWritingContext
      Parameters:
      definition - the assembly definition describing the root element
      item - the bound object to serialize as the root element
      Throws:
      IOException - if an error occurs during writing