Interface IConfigValueSerializer<T>

Type Parameters:
T - effectively immutable value type with stable equality
All Known Subinterfaces:
IConfigKeyValueSerializer<T,K,V>, IConfigListValueSerializer<T>

public interface IConfigValueSerializer<T>
Teaches MezzConfig how to store, validate, and describe a mod-specific value type.

Prefer built-in value methods when possible. For a custom type, implement this interface and pass it to IConfigCategoryBuilder.addValue(String, Object, IConfigValueSerializer). Implement IConfigListValueSerializer when editors should work with list elements individually, or IConfigKeyValueSerializer when editors should work with two components of an entry.

Accepted values must be effectively immutable with stable equality. Serialization must be deterministic, and every accepted value must deserialize back to an equal value without diagnostics. Deserialization must report invalid input through IDeserializeResult rather than throw; every returned value must pass isValid(Object). Shared serializer instances must be thread-safe.

Since:
0.1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    Parse stored text, returning diagnostics instead of throwing when the input is invalid.
    default @Unmodifiable Optional<List<T>>
    List every valid choice when config editors should present a fixed selection.
    Describe an inclusive range that config editors can present with a bounded control.
    Describe valid input for config editors and error messages.
    boolean
    isValid(T value)
    Return whether this value can be safely stored.
    serialize(T value)
    Convert a valid value to its stable text representation.
  • Method Details

    • serialize

      String serialize(T value)
      Convert a valid value to its stable text representation.
      Since:
      0.1.0
    • deserialize

      IDeserializeResult<T> deserialize(String string)
      Parse stored text, returning diagnostics instead of throwing when the input is invalid.
      Since:
      0.1.0
    • isValid

      boolean isValid(T value)
      Return whether this value can be safely stored.
      Since:
      0.1.0
    • getRange

      default Optional<ConfigValueRange<T>> getRange()
      Describe an inclusive range that config editors can present with a bounded control.
      Since:
      0.1.0
    • getAllValidValues

      default @Unmodifiable Optional<List<T>> getAllValidValues()
      List every valid choice when config editors should present a fixed selection.

      The returned list must be unmodifiable and duplicate-free. Its order must remain stable while the set of valid values is unchanged. Return Optional.empty() for open-ended value types.

      Since:
      0.1.0
    • getValidValuesDescription

      String getValidValuesDescription()
      Describe valid input for config editors and error messages.
      Since:
      0.1.0