Package dev.polv.taleapi.config
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 TypeMethodDescription<T> Tdeserialize(Reader reader, Class<T> type) Deserializes configuration data from a reader into an object of the specified type.deserializeToNode(Reader reader) Deserializes configuration data from a reader into a traversableConfigNode.Returns the file extension associated with this provider's format.default StringReturns a human-readable name for this format.voidserialize(Writer writer, ConfigNode node) Serializes aConfigNodeand writes it to the given writer.<T> voidSerializes a configuration object and writes it to the given writer.
-
Method Details
-
deserialize
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 fromtype- the class of the object to deserialize into- Returns:
- the deserialized configuration object
- Throws:
ConfigException- if deserialization fails
-
deserializeToNode
Deserializes configuration data from a reader into a traversableConfigNode.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
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 tovalue- the configuration object to serialize- Throws:
ConfigException- if serialization fails
-
serialize
Serializes aConfigNodeand writes it to the given writer.- Parameters:
writer- the writer to write the serialized data tonode- 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
Returns a human-readable name for this format.- Returns:
- the format name (e.g., "JSON", "YAML")
-