Class Serializer

java.lang.Object
us.irdev.bedrock.bag.Serializer

public class Serializer extends Object
  • Field Details

  • Constructor Details

    • Serializer

      public Serializer()
  • Method Details

    • Unwrap

      public static BagObject Unwrap(BagObject bagObject)
      Return the @value component of a serialized object
      Parameters:
      bagObject - the BagObject representing the serialized object.
      Returns:
      A BagObject from the @value component, or null if it's not a valid serialization.
    • toBagObject

      public static BagObject toBagObject(Object object)
      Convert the given object to a BagObject representation that can be used to reconstitute the given object after serialization.
      Parameters:
      object - the target element to serialize. It must be one of the following: primitive, boxed-primitive, Plain Old Java Object (POJO) class, object class with getters and setters for all members, BagObject, BagArray, array, or list or map-based container of one of the previously mentioned types.
      Returns:
      A BagObject encapsulation of the target object, or null if the conversion failed.
    • fromBagObject

      public static <WorkingType> WorkingType fromBagObject(BagObject bagObject)
      Reconstitute the given BagObject representation back to the object it represents.
      Type Parameters:
      WorkingType - template parameter for the type to return
      Parameters:
      bagObject - the target BagObject to deserialize. It must be a valid representation of the encoded type(i.e. created by the toBagObject method).
      Returns:
      the reconstituted object, or null if the reconstitution failed.
    • fromBagAsType

      public static <WorkingType> WorkingType fromBagAsType(Bag bag, Class type)
      Reconstitute the given BagObject representation back to the object it represents, using a "best-effort" approach to matching the fields of the BagObject to the class being initialized.
      Parameters:
      bag - The input data to reconstruct from, either a BagObject or BagArray
      type - the Class representing the type to reconstruct
      Returns:
      the reconstituted object, or null if the reconstitution failed.