Class YamlOps

java.lang.Object
com.github.darksoulq.abyssallib.common.serialization.DynamicOps<Object>
com.github.darksoulq.abyssallib.common.serialization.ops.YamlOps

public class YamlOps extends DynamicOps<Object>
A DynamicOps implementation backed by SnakeYAML.

This implementation represents YAML data as plain Java objects (Map, List, primitives), enabling serialization and deserialization of hierarchical structures in a generic form.

  • Field Details

    • INSTANCE

      public static final YamlOps INSTANCE
      Singleton instance of YamlOps.
  • Method Details

    • createString

      public Object createString(String value)
      Creates a string value.
      Specified by:
      createString in class DynamicOps<Object>
      Parameters:
      value - the string
      Returns:
      the same string object
    • createByte

      public Object createByte(byte value)
      Creates a byte value.
      Specified by:
      createByte in class DynamicOps<Object>
      Parameters:
      value - the byte
      Returns:
      boxed byte
    • createShort

      public Object createShort(short value)
      Creates a short value.
      Specified by:
      createShort in class DynamicOps<Object>
      Parameters:
      value - the short
      Returns:
      boxed short
    • createInt

      public Object createInt(int value)
      Creates an int value.
      Specified by:
      createInt in class DynamicOps<Object>
      Parameters:
      value - the int
      Returns:
      boxed integer
    • createLong

      public Object createLong(long value)
      Creates a long value.
      Specified by:
      createLong in class DynamicOps<Object>
      Parameters:
      value - the long
      Returns:
      boxed long
    • createFloat

      public Object createFloat(float value)
      Creates a float value.
      Specified by:
      createFloat in class DynamicOps<Object>
      Parameters:
      value - the float
      Returns:
      boxed float
    • createDouble

      public Object createDouble(double value)
      Creates a double value.
      Specified by:
      createDouble in class DynamicOps<Object>
      Parameters:
      value - the double
      Returns:
      boxed double
    • createBoolean

      public Object createBoolean(boolean value)
      Creates a boolean value.
      Specified by:
      createBoolean in class DynamicOps<Object>
      Parameters:
      value - the boolean
      Returns:
      boxed boolean
    • createList

      public Object createList(List<Object> elements)
      Creates a YAML list.
      Specified by:
      createList in class DynamicOps<Object>
      Parameters:
      elements - list elements
      Returns:
      mutable ArrayList containing elements
    • createMap

      public Object createMap(Map<Object,Object> map)
      Creates a YAML map.
      Specified by:
      createMap in class DynamicOps<Object>
      Parameters:
      map - key-value pairs
      Returns:
      ordered LinkedHashMap copy
    • getStringValue

      public Optional<String> getStringValue(Object input)
      Extracts a string value if possible.
      Specified by:
      getStringValue in class DynamicOps<Object>
      Parameters:
      input - input object
      Returns:
      optional string
    • getNumberValue

      public Optional<Number> getNumberValue(Object input)
      Extracts a numeric value if possible.
      Specified by:
      getNumberValue in class DynamicOps<Object>
      Parameters:
      input - input object
      Returns:
      optional number
    • getIntValue

      public Optional<Integer> getIntValue(Object input)
      Extracts an integer value if possible.
      Specified by:
      getIntValue in class DynamicOps<Object>
      Parameters:
      input - input object
      Returns:
      optional int
    • getLongValue

      public Optional<Long> getLongValue(Object input)
      Extracts a long value if possible.
      Specified by:
      getLongValue in class DynamicOps<Object>
      Parameters:
      input - input object
      Returns:
      optional long
    • getFloatValue

      public Optional<Float> getFloatValue(Object input)
      Extracts a float value if possible.
      Specified by:
      getFloatValue in class DynamicOps<Object>
      Parameters:
      input - input object
      Returns:
      optional float
    • getDoubleValue

      public Optional<Double> getDoubleValue(Object input)
      Extracts a double value if possible.
      Specified by:
      getDoubleValue in class DynamicOps<Object>
      Parameters:
      input - input object
      Returns:
      optional double
    • getBooleanValue

      public Optional<Boolean> getBooleanValue(Object input)
      Extracts a boolean value if possible.
      Specified by:
      getBooleanValue in class DynamicOps<Object>
      Parameters:
      input - input object
      Returns:
      optional boolean
    • getList

      public Optional<List<Object>> getList(Object input)
      Extracts a list if the input is a list.
      Specified by:
      getList in class DynamicOps<Object>
      Parameters:
      input - input object
      Returns:
      optional list
    • getMap

      public Optional<Map<Object,Object>> getMap(Object input)
      Extracts a map if the input is a map.
      Specified by:
      getMap in class DynamicOps<Object>
      Parameters:
      input - input object
      Returns:
      optional map
    • getKeys

      public Optional<Iterable<String>> getKeys(Object input)
      Returns map keys as strings if input is a map.
      Specified by:
      getKeys in class DynamicOps<Object>
      Parameters:
      input - input object
      Returns:
      iterable of keys
    • size

      public OptionalInt size(Object input)
      Returns the size of a collection or map.
      Specified by:
      size in class DynamicOps<Object>
      Parameters:
      input - input object
      Returns:
      optional size
    • copy

      public Object copy(Object input)
      Creates a deep copy of a YAML structure.
      Specified by:
      copy in class DynamicOps<Object>
      Parameters:
      input - input object
      Returns:
      deep-copied structure
    • empty

      public Object empty()
      Returns the YAML empty value representation.
      Specified by:
      empty in class DynamicOps<Object>
      Returns:
      null
    • parse

      public Object parse(String yamlText)
      Parses YAML text into a normalized object graph.
      Parameters:
      yamlText - YAML string
      Returns:
      parsed object structure
    • parse

      public Object parse(InputStream in)
      Parses YAML from an input stream.
      Parameters:
      in - input stream
      Returns:
      parsed object structure
    • dump

      public static String dump(Object obj)
      Serializes a Java object into YAML.
      Parameters:
      obj - object
      Returns:
      YAML string