Class CharMarshaller

java.lang.Object
org.apache.juneau.marshaller.Marshaller
org.apache.juneau.marshaller.CharMarshaller
Direct Known Subclasses:
Csv, Html, Json, Json5, OpenApi, PlainText, Uon, UrlEncoding, Xml

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

    • CharMarshaller

      Constructor.
      Parameters:
      s - The serializer to use for serializing output.
      Must not be null.
      p - The parser to use for parsing input.
      Must not be null.
  • Method Details

    • read

      public final <T> T read(String input, Class<T> type) throws ParseException
      Same as Marshaller.read(Object,Class) but reads from a string 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(String input, Type type, Type... args) throws ParseException
      Same as Marshaller.read(Object,Type,Type...) but reads from a string 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 String write(Object object) throws SerializeException
      Serializes a POJO directly to a String.
      Parameters:
      object - The object to serialize.
      Returns:
      The serialized object.
      Throws:
      SerializeException - If a problem occurred trying to convert the output.