Class StreamMarshaller

java.lang.Object
org.apache.juneau.marshaller.Marshaller
org.apache.juneau.marshaller.StreamMarshaller
Direct Known Subclasses:
MsgPack

public class StreamMarshaller extends Marshaller
A subclass of Marshaller for stream-based serializers and parsers.
See Also:
  • Constructor Details

  • Method Details

    • read

      public final <T> T read(byte[] input, Class<T> type) throws ParseException
      Same as Marshaller.read(Object,Class) but reads from a byte array and thus doesn't throw an IOException.

      This is the preferred parse method for simple types since you don't need to cast the results.

      Examples:

      Marshaller marshaller = Json.DEFAULT; // Parse into a string. String string = marshaller .read(json, String.class); // Parse into a bean. MyBean bean = marshaller .read(json, MyBean.class); // Parse into a bean array. MyBean[] beanArray = marshaller .read(json, MyBean[].class); // Parse into a linked-list of objects. List list = marshaller .read(json, LinkedList.class); // Parse into a map of object keys/values. Map map = marshaller .read(json, TreeMap.class);

      Type Parameters:
      T - The class type of the object being created.
      Parameters:
      input - The input.
      type - The object type to create.
      Returns:
      The parsed object.
      Throws:
      ParseException - Malformed input encountered.
    • read

      public final <T> T read(byte[] input, Type type, Type... args) throws ParseException
      Same as Marshaller.read(Object,Type,Type...) but reads from a byte array and thus doesn't throw an IOException.
      Type Parameters:
      T - The class type of the object to create.
      Parameters:
      input - The input.
      type - The object type to create.
      Can be any of the following: ClassMeta, Class, ParameterizedType, GenericArrayType
      args - The type arguments of the class if it's a collection or map.
      Can be any of the following: ClassMeta, Class, ParameterizedType, GenericArrayType
      Ignored if the main type is not a map or collection.
      Returns:
      The parsed object.
      Throws:
      ParseException - Malformed input encountered.
      See Also:
    • write

      public final byte[] write(Object o) throws SerializeException
      Serializes a POJO directly to a byte[].
      Parameters:
      o - The object to serialize.
      Returns:
      The serialized object.
      Throws:
      SerializeException - If a problem occurred trying to convert the output.