001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package gov.nist.secauto.metaschema.databind.io;
007
008import gov.nist.secauto.metaschema.core.configuration.IConfiguration;
009import gov.nist.secauto.metaschema.core.configuration.IMutableConfiguration;
010import gov.nist.secauto.metaschema.core.model.IBoundObject;
011import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly;
012
013import edu.umd.cs.findbugs.annotations.NonNull;
014
015/**
016 * The base class of all format-specific serializers.
017 *
018 * @param <CLASS>
019 *          the bound class to serialize from
020 */
021public abstract class AbstractSerializer<CLASS extends IBoundObject>
022    extends AbstractSerializationBase<SerializationFeature<?>>
023    implements ISerializer<CLASS> {
024
025  /**
026   * Construct a new serializer.
027   *
028   * @param definition
029   *          the bound class information for the Java type this serializer is
030   *          operating on
031   */
032  public AbstractSerializer(@NonNull IBoundDefinitionModelAssembly definition) {
033    super(definition);
034  }
035
036  @Override
037  public ISerializer<CLASS> enableFeature(SerializationFeature<?> feature) {
038    return set(feature, true);
039  }
040
041  @Override
042  public ISerializer<CLASS> disableFeature(SerializationFeature<?> feature) {
043    return set(feature, false);
044  }
045
046  @Override
047  public ISerializer<CLASS> applyConfiguration(
048      @NonNull IConfiguration<SerializationFeature<?>> other) {
049    IMutableConfiguration<SerializationFeature<?>> config = getConfiguration();
050    config.applyConfiguration(other);
051    configurationChanged(config);
052    return this;
053  }
054
055  @Override
056  public ISerializer<CLASS> set(SerializationFeature<?> feature, Object value) {
057    IMutableConfiguration<SerializationFeature<?>> config = getConfiguration();
058    config.set(feature, value);
059    configurationChanged(config);
060    return this;
061  }
062}