Class DefaultXmlSerializer<CLASS extends IBoundObject>

java.lang.Object
dev.metaschema.databind.io.AbstractSerializer<CLASS>
dev.metaschema.databind.io.xml.DefaultXmlSerializer<CLASS>
Type Parameters:
CLASS - the Java type of the bound object to be serialized
All Implemented Interfaces:
IConfiguration<SerializationFeature<?>>, IMutableConfiguration<SerializationFeature<?>>, ISerializer<CLASS>

public class DefaultXmlSerializer<CLASS extends IBoundObject> extends AbstractSerializer<CLASS>
Provides support for serializing bound Java objects to XML format based on a Metaschema module definition.

This serializer uses StAX's XMLStreamWriter2 to produce XML output that conforms to the Metaschema-defined data structure.

  • Constructor Details

    • DefaultXmlSerializer

      public DefaultXmlSerializer(@NonNull IBoundDefinitionModelAssembly definition)
      Construct a new XML serializer based on the top-level assembly indicated by the provided classBinding.
      Parameters:
      definition - the bound Module assembly definition that describes the data to serialize
  • Method Details

    • resetFactory

      protected final void resetFactory()
      Resets the XML output factory to use a freshly created instance.

      This method is called when the serializer configuration changes to ensure the factory reflects the current settings.

    • configurationChanged

      protected void configurationChanged(IMutableConfiguration<SerializationFeature<?>> config)
      Callback method invoked when the configuration has been changed.

      Subclasses can override this method to handle configuration changes, such as resetting cached factory instances.

      Parameters:
      config - the updated configuration
    • newFactoryInstance

      @NonNull protected org.codehaus.stax2.XMLOutputFactory2 newFactoryInstance()
      Get a JSON factory instance.

      This method can be used by sub-classes to create a customized factory instance.

      Returns:
      the factory
    • getXMLOutputFactory

      @NonNull protected final org.codehaus.stax2.XMLOutputFactory2 getXMLOutputFactory()
      Get the configured XML output factory used to create XMLStreamWriter2 instances.
      Returns:
      the factory
    • newXMLStreamWriter

      @NonNull protected final org.codehaus.stax2.XMLStreamWriter2 newXMLStreamWriter(@NonNull Writer writer) throws IOException
      Create a new stream writer using the provided writer.
      Parameters:
      writer - the writer to use for output
      Returns:
      the stream writer created by the output factory
      Throws:
      IOException - if an error occurred while creating the writer
    • serialize

      public void serialize(IBoundObject data, Writer writer) throws IOException
      Description copied from interface: ISerializer
      Write data from a bound class instance to the Writer.
      Parameters:
      data - the instance data
      writer - the writer to write to
      Throws:
      IOException - if an error occurred while writing data to the stream
    • getBindingContext

      @NonNull protected IBindingContext getBindingContext()
      Retrieve the binding context associated with the serializer.
      Returns:
      the binding context
    • getDefinition

      @NonNull protected IBoundDefinitionModelAssembly getDefinition()
      Retrieve the bound class information associated with the assembly that the serializer/deserializer will write/read data from.
      Returns:
      the class binding for the Module assembly
    • getConfiguration

      @NonNull protected IMutableConfiguration<SerializationFeature<?>> getConfiguration()
      Get the current configuration of the serializer/deserializer.
      Returns:
      the configuration
    • isFeatureEnabled

      public boolean isFeatureEnabled(SerializationFeature<?> feature)
      Description copied from interface: IConfiguration
      Determines if a specific feature is enabled.
      Specified by:
      isFeatureEnabled in interface IConfiguration<T extends IConfigurationFeature<?>>
      Parameters:
      feature - the feature to check for
      Returns:
      true if the feature is enabled, or false otherwise
      See Also:
    • getFeatureValues

      public Map<SerializationFeature<?>,Object> getFeatureValues()
      Description copied from interface: IConfiguration
      Get the mapping of each feature mapped to its value.
      Specified by:
      getFeatureValues in interface IConfiguration<T extends IConfigurationFeature<?>>
      Returns:
      the mapping
    • get

      public <V> V get(SerializationFeature<?> feature)
      Description copied from interface: IConfiguration
      Get the configuration value of the provided feature.
      Specified by:
      get in interface IConfiguration<T extends IConfigurationFeature<?>>
      Type Parameters:
      V - the value type
      Parameters:
      feature - the requested feature
      Returns:
      the value of the feature