Interface ConfigProvider

All Known Implementing Classes:
JsonProvider

public interface ConfigProvider
Interface for configuration format providers.

Implementations handle serialization and deserialization for specific formats (e.g., JSON, YAML, TOML). Each provider manages a single format type.

Example Implementation


 public class JsonProvider implements ConfigProvider {
   @Override
   public <T> T deserialize(Reader reader, Class<T> type) throws ConfigException {
     // Parse JSON and return typed object
   }

   @Override
   public ConfigNode deserializeToNode(Reader reader) throws ConfigException {
     // Parse JSON and return a traversable node
   }

   @Override
   public <T> void serialize(Writer writer, T value) throws ConfigException {
     // Write object as JSON
   }

   @Override
   public String fileExtension() {
     return "json";
   }
 }
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    deserialize(Reader reader, Class<T> type)
    Deserializes configuration data from a reader into an object of the specified type.
    Deserializes configuration data from a reader into a traversable ConfigNode.
    Returns the file extension associated with this provider's format.
    default String
    Returns a human-readable name for this format.
    void
    serialize(Writer writer, ConfigNode node)
    Serializes a ConfigNode and writes it to the given writer.
    <T> void
    serialize(Writer writer, T value)
    Serializes a configuration object and writes it to the given writer.
  • Method Details

    • deserialize

      <T> T deserialize(Reader reader, Class<T> type) throws ConfigException
      Deserializes configuration data from a reader into an object of the specified type.
      Type Parameters:
      T - the type of the configuration object
      Parameters:
      reader - the reader to read configuration data from
      type - the class of the object to deserialize into
      Returns:
      the deserialized configuration object
      Throws:
      ConfigException - if deserialization fails
    • deserializeToNode

      ConfigNode deserializeToNode(Reader reader) throws ConfigException
      Deserializes configuration data from a reader into a traversable ConfigNode.

      Use this when you want dynamic access to configuration values without defining a specific class structure.

      Parameters:
      reader - the reader to read configuration data from
      Returns:
      the configuration as a traversable node
      Throws:
      ConfigException - if deserialization fails
    • serialize

      <T> void serialize(Writer writer, T value) throws ConfigException
      Serializes a configuration object and writes it to the given writer.
      Type Parameters:
      T - the type of the configuration object
      Parameters:
      writer - the writer to write the serialized data to
      value - the configuration object to serialize
      Throws:
      ConfigException - if serialization fails
    • serialize

      void serialize(Writer writer, ConfigNode node) throws ConfigException
      Serializes a ConfigNode and writes it to the given writer.
      Parameters:
      writer - the writer to write the serialized data to
      node - the configuration node to serialize
      Throws:
      ConfigException - if serialization fails
    • fileExtension

      String fileExtension()
      Returns the file extension associated with this provider's format.

      The extension should not include the leading dot (e.g., "json" not ".json").

      Returns:
      the file extension for this format
    • formatName

      default String formatName()
      Returns a human-readable name for this format.
      Returns:
      the format name (e.g., "JSON", "YAML")