Interface Marshaller

All Known Implementing Classes:
MarshallerImpl

public interface Marshaller
  • Method Summary

    Modifier and Type
    Method
    Description
    <E> E
    marshall(Class<E> clazz, JsonElement elem)
    Unpacks the provided JsonElement into a new object of type clazz, making a best effort to unpack all the fields it can.
    <E> E
    marshall(Type type, JsonElement elem)
    Unpacks the provided JsonElement into an object of the provided Type, and force-casts it to E.
    <E> E
    Unpacks the provided JsonElement in fail-fast mode.
    Turns a java object into its json intermediate representation.
  • Method Details

    • serialize

      JsonElement serialize(Object obj)
      Turns a java object into its json intermediate representation.
    • marshall

      <E> E marshall(Class<E> clazz, JsonElement elem)
      Unpacks the provided JsonElement into a new object of type clazz, making a best effort to unpack all the fields it can. Any fields that cannot be unpacked will be left in the state the initializer and no-arg constructor leaves them in.

      Note: Consider using marshallCarefully(Class, JsonElement) to detect errors first, and then calling this method as a fallback if an error is encountered.

      Type Parameters:
      E - The type of the object to create and deserialize
      Parameters:
      clazz - The class of the object to create and deserialize
      elem - json intermediate representation of the data to be unpacked.
      Returns:
      A new object of the provided class that represents the data in the json provided.
    • marshall

      <E> E marshall(Type type, JsonElement elem)
      Unpacks the provided JsonElement into an object of the provided Type, and force-casts it to E.
      Type Parameters:
      E - The type to force-cast to at the end
      Parameters:
      type - The type to deserialize to
      elem - json intermediate representation of the data to be unpacked.
      Returns:
      A new object of the provided Type that represents the data in the json provided.
    • marshallCarefully

      <E> E marshallCarefully(Class<E> clazz, JsonElement elem) throws DeserializationException
      Unpacks the provided JsonElement in fail-fast mode. A detailed exception is thrown for any problem encountered during the unpacking process.
      Type Parameters:
      E - The type of the object to create and deserialize
      Parameters:
      clazz - The class of the object to create and deserialize
      elem - json intermediate representation of the data to be unpacked.
      Returns:
      A new object of the provided class that represents the data in the json provided.
      Throws:
      DeserializationException - if any problems are encountered unpacking the data.