Class ParsedReaderSwap

java.lang.Object
org.apache.juneau.swap.ObjectSwap<Reader,Object>
org.apache.juneau.swaps.ParsedReaderSwap
Direct Known Subclasses:
ParsedReaderSwap.Html, ParsedReaderSwap.Json, ParsedReaderSwap.PlainText, ParsedReaderSwap.Uon, ParsedReaderSwap.UrlEncoding, ParsedReaderSwap.Xml

Transforms the contents of a Reader into an Object.
Description
The Reader must contain JSON, Juneau-generated XML (output from XmlSerializer), or Juneau-generated HTML (output from JsonSerializer) in order to be parsed correctly.

Useful for serializing models that contain Readers created by RestCall instances.

This is a one-way transform, since Readers cannot be reconstituted.

Behavior-specific subclasses
The following direct subclasses are provided for convenience:
See Also:
  • Constructor Details

    • ParsedReaderSwap

      Parameters:
      parser - The parser to use to convert the contents of the reader to Java objects.
  • Method Details

    • swap

      public Object swap(BeanSession session, Reader o) throws Exception
      Converts the specified Reader to an Object whose type is determined by the contents of the reader.
      Overrides:
      swap in class ObjectSwap<Reader,Object>
      Parameters:
      session - The bean session to use to get the class meta. This is always going to be the same bean context that created this swap.
      o - The object to be transformed.
      Returns:
      The transformed object.
      Throws:
      Exception - If a problem occurred trying to convert the output.