Module dev.metaschema.databind
Package dev.metaschema.databind.io.json
Class DefaultJsonSerializer<CLASS extends IBoundObject>
java.lang.Object
dev.metaschema.databind.io.AbstractSerializer<CLASS>
dev.metaschema.databind.io.json.DefaultJsonSerializer<CLASS>
- Type Parameters:
CLASS- the Java type of the bound object to be serialized
- All Implemented Interfaces:
IConfiguration<SerializationFeature<?>>,IMutableConfiguration<SerializationFeature<?>>,ISerializer<CLASS>
- Direct Known Subclasses:
DefaultYamlSerializer
Provides support for serializing bound Java objects to JSON format based on a
Metaschema module definition.
This serializer uses Jackson's JsonGenerator to produce JSON output
that conforms to the Metaschema-defined data structure.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultJsonSerializer(IBoundDefinitionModelAssembly definition) Construct a new Module binding-based deserializer that reads JSON-based Module content. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCallback method invoked when the configuration has been changed.<V> Vget(SerializationFeature<?> feature) Get the configuration value of the providedfeature.protected IBindingContextRetrieve the binding context associated with the serializer.protected 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.Get the mapping of each feature mapped to its value.booleanisFeatureEnabled(SerializationFeature<?> feature) Determines if a specific feature is enabled.protected com.fasterxml.jackson.core.JsonFactoryConstructs a new JSON factory.protected final voidResets the JSON factory to use a freshly created instance.voidserialize(IBoundObject data, Writer writer) Write 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
-
DefaultJsonSerializer
Construct a new Module binding-based deserializer that reads JSON-based Module content.- Parameters:
definition- the assembly class binding describing the Java objects this deserializer parses data into
-
-
Method Details
-
resetFactory
protected final void resetFactory()Resets the JSON 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
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 com.fasterxml.jackson.core.JsonFactory newFactoryInstance()Constructs a new JSON factory.Subclasses can override this method to create a JSON factory with a specific configuration.
- Returns:
- the factory
-
serialize
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
Get the current configuration of the serializer/deserializer.- Returns:
- the configuration
-
isFeatureEnabled
Description copied from interface:IConfigurationDetermines if a specific feature is enabled.- Specified by:
isFeatureEnabledin interfaceIConfiguration<T extends IConfigurationFeature<?>>- Parameters:
feature- the feature to check for- Returns:
trueif the feature is enabled, orfalseotherwise- See Also:
-
getFeatureValues
Description copied from interface:IConfigurationGet the mapping of each feature mapped to its value.- Specified by:
getFeatureValuesin interfaceIConfiguration<T extends IConfigurationFeature<?>>- Returns:
- the mapping
-
get
Description copied from interface:IConfigurationGet the configuration value of the providedfeature.- Specified by:
getin interfaceIConfiguration<T extends IConfigurationFeature<?>>- Type Parameters:
V- the value type- Parameters:
feature- the requested feature- Returns:
- the value of the feature
-