Module dev.metaschema.databind
Package dev.metaschema.databind.io.xml
Class DefaultXmlSerializer<CLASS extends dev.metaschema.core.model.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:
dev.metaschema.core.configuration.IConfiguration<SerializationFeature<?>>,dev.metaschema.core.configuration.IMutableConfiguration<SerializationFeature<?>>,ISerializer<CLASS>
public class DefaultXmlSerializer<CLASS extends dev.metaschema.core.model.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 Summary
ConstructorsConstructorDescriptionDefaultXmlSerializer(IBoundDefinitionModelAssembly definition) Construct a new XML serializer based on the top-level assembly indicated by the providedclassBinding. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconfigurationChanged(dev.metaschema.core.configuration.IMutableConfiguration<SerializationFeature<?>> config) Callback method invoked when the configuration has been changed.<V> Vget(SerializationFeature<?> feature) protected IBindingContextRetrieve the binding context associated with the serializer.protected dev.metaschema.core.configuration.IMutableConfiguration<SerializationFeature<?>>Get the current configuration of the serializer/deserializer.protected IBoundDefinitionModelAssemblyRetrieve the bound class information associated with the assembly that the serializer/deserializer will write/read data from.protected final org.codehaus.stax2.XMLOutputFactory2Get the configured XML output factory used to createXMLStreamWriter2instances.booleanisFeatureEnabled(SerializationFeature<?> feature) protected org.codehaus.stax2.XMLOutputFactory2Get a JSON factory instance.protected final org.codehaus.stax2.XMLStreamWriter2newXMLStreamWriter(Writer writer) Create a new stream writer using the provided writer.protected final voidResets the XML output factory to use a freshly created instance.voidWrite data from a bound class instance to theWriter.Methods inherited from class dev.metaschema.databind.io.AbstractSerializer
applyConfiguration, disableFeature, enableFeature, setMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.metaschema.core.configuration.IConfiguration
get, getFeatureValues, isFeatureEnabledMethods inherited from interface dev.metaschema.databind.io.ISerializer
serialize, serialize, serialize
-
Constructor Details
-
DefaultXmlSerializer
Construct a new XML serializer based on the top-level assembly indicated by the providedclassBinding.- Parameters:
definition- the bound Module assembly definition that describes the data to serialize
-
-
Method Details
-
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(dev.metaschema.core.configuration.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
Get a JSON factory instance.This method can be used by sub-classes to create a customized factory instance.
- Returns:
- the factory
-
getXMLOutputFactory
Get the configured XML output factory used to createXMLStreamWriter2instances.- 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(dev.metaschema.core.model.IBoundObject data, Writer writer) throws IOException Description copied from interface:ISerializerWrite data from a bound class instance to theWriter.- Parameters:
data- the instance datawriter- the writer to write to- Throws:
IOException- if an error occurred while writing data to the stream
-
getBindingContext
Retrieve the binding context associated with the serializer.- Returns:
- the binding context
-
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 dev.metaschema.core.configuration.IMutableConfiguration<SerializationFeature<?>> getConfiguration()Get the current configuration of the serializer/deserializer.- Returns:
- the configuration
-
isFeatureEnabled
- Specified by:
isFeatureEnabledin interfacedev.metaschema.core.configuration.IConfiguration<T extends dev.metaschema.core.configuration.IConfigurationFeature<?>>
-
getFeatureValues
- Specified by:
getFeatureValuesin interfacedev.metaschema.core.configuration.IConfiguration<T extends dev.metaschema.core.configuration.IConfigurationFeature<?>>
-
get
- Specified by:
getin interfacedev.metaschema.core.configuration.IConfiguration<T extends dev.metaschema.core.configuration.IConfigurationFeature<?>>
-