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

public class DefaultJsonSerializer<CLASS extends IBoundObject> extends AbstractSerializer<CLASS>
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 Details

    • DefaultJsonSerializer

      public DefaultJsonSerializer(@NonNull IBoundDefinitionModelAssembly definition)
      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

      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 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

      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