Interface Parser<T>

Type Parameters:
T - the type to parse/serialize
All Known Implementing Classes:
ConfigParser, DefaultConfigParser, StringHashMapParser

public interface Parser<T>
Generic parser interface for serialization and deserialization.

Provides bidirectional conversion between objects and their serialized form. Implementations should handle type conversion for configuration files, database storage, or other persistence mechanisms.

Example Implementation:


 public class LocationParser implements Parser<Location> {
     public Location parse(Object object) {
         Map<String, Object> map = (Map<String, Object>) object;
         return new Location(
             Bukkit.getWorld((String) map.get("world")),
             (double) map.get("x"),
             (double) map.get("y"),
             (double) map.get("z")
         );
     }

     public Object serialize(Location location) {
         Map<String, Object> map = new HashMap<>();
         map.put("world", location.getWorld().getName());
         map.put("x", location.getX());
         map.put("y", location.getY());
         map.put("z", location.getZ());
         return map;
     }
 }
 
Since:
6.0.0
Author:
wisdomme
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    parse(Object object)
    Parses a raw object into the target type.
    serialize(T object)
    Serializes an object to a storable format.
  • Method Details

    • parse

      T parse(Object object)
      Parses a raw object into the target type.
      Parameters:
      object - the raw object to parse (typically from configuration)
      Returns:
      the parsed object of type T
    • serialize

      Object serialize(T object)
      Serializes an object to a storable format.
      Parameters:
      object - the object to serialize
      Returns:
      the serialized form (typically Map, List, or primitive types)