Class UonParserSession

All Implemented Interfaces:
HttpPartParserSession
Direct Known Subclasses:
OpenApiParserSession, UrlEncodingParserSession

Session object that lives for the duration of a single use of UonParser.
Notes:
  • This class is not thread safe and is typically discarded after one use.
See Also:
  • Constructor Details

  • Method Details

    • create

      Creates a new builder for this object.
      Parameters:
      ctx - The context creating this session.
      Returns:
      A new builder.
    • doParse

      protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws IOException, ParseException, ExecutableException
      Description copied from class: ParserSession
      Workhorse method.

      Subclasses are expected to implement this method or Parser.doParse(ParserSession,ParserPipe,ClassMeta).

      The default implementation of this method simply calls Parser.doParse(ParserSession,ParserPipe,ClassMeta).

      Overrides:
      doParse in class ParserSession
      Type Parameters:
      T - The class type of the object to create.
      Parameters:
      pipe - Where to get the input from.
      type - The class type of the object to create. If null or Object.class, object type is based on what's being parsed. For example, when parsing JSON text, it may return a String, Number, JsonMap, etc...
      Returns:
      The parsed object.
      Throws:
      IOException - Thrown by underlying stream.
      ParseException - Malformed input encountered.
      ExecutableException - Exception occurred on invoked constructor/method/field.
    • doParseIntoMap

      protected <K, V> Map<K,V> doParseIntoMap(ParserPipe pipe, Map<K,V> m, Type keyType, Type valueType) throws Exception
      Description copied from class: ParserSession
      Implementation method.

      Default implementation throws an UnsupportedOperationException.

      Overrides:
      doParseIntoMap in class ParserSession
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      pipe - The parser input.
      m - The map being loaded.
      keyType - The class type of the keys, or null to default to String.class.
      valueType - The class type of the values, or null to default to whatever is being parsed.
      Returns:
      The same map that was passed in to allow this method to be chained.
      Throws:
      Exception - If thrown from underlying stream, or if the input contains a syntax error or is malformed.
    • doParseIntoCollection

      protected <E> Collection<E> doParseIntoCollection(ParserPipe pipe, Collection<E> c, Type elementType) throws Exception
      Description copied from class: ParserSession
      Implementation method.

      Default implementation throws an UnsupportedOperationException.

      Overrides:
      doParseIntoCollection in class ParserSession
      Type Parameters:
      E - The element type.
      Parameters:
      pipe - The parser input.
      c - The collection being loaded.
      elementType - The class type of the elements, or null to default to whatever is being parsed.
      Returns:
      The same collection that was passed in to allow this method to be chained.
      Throws:
      Exception - If thrown from underlying stream, or if the input contains a syntax error or is malformed.
    • parse

      public <T> T parse(HttpPartType partType, HttpPartSchema schema, String in, ClassMeta<T> toType) throws ParseException, SchemaValidationException
      Description copied from interface: HttpPartParserSession
      Converts the specified input to the specified class type.
      Specified by:
      parse in interface HttpPartParserSession
      Type Parameters:
      T - The POJO type to transform the input into.
      Parameters:
      partType - The part type being parsed.
      schema - Schema information about the part.
      May be null.
      Not all part parsers use the schema information.
      in - The input being parsed.
      toType - The POJO type to transform the input into.
      Returns:
      The parsed value.
      Throws:
      ParseException - Malformed input encountered.
      SchemaValidationException - If the input or resulting HTTP part object fails schema validation.
    • parseAnything

      public <T> T parseAnything(ClassMeta<?> eType, UonReader r, Object outer, boolean isUrlParamValue, BeanPropertyMeta pMeta) throws IOException, ParseException, ExecutableException
      Workhorse method.
      Type Parameters:
      T - The class type being parsed, or null if unknown.
      Parameters:
      eType - The class type being parsed, or null if unknown.
      r - The reader being parsed.
      outer - The outer object (for constructing nested inner classes).
      isUrlParamValue - If true, then we're parsing a top-level URL-encoded value which is treated a bit different than the default case.
      pMeta - The current bean property being parsed.
      Returns:
      The parsed object.
      Throws:
      IOException - Thrown by underlying stream.
      ParseException - Malformed input encountered.
      ExecutableException - Exception occurred on invoked constructor/method/field.
    • parseAttr

      protected final Object parseAttr(UonReader r, boolean encoded) throws IOException, ParseException
      Convenience method for parsing an attribute from the specified parser.
      Parameters:
      r - The reader.
      encoded - Whether the attribute is encoded.
      Returns:
      The parsed object
      Throws:
      IOException - Exception thrown by underlying stream.
      ParseException - Attribute was malformed.
    • parseAttrName

      protected final String parseAttrName(UonReader r, boolean encoded) throws IOException, ParseException
      Parses an attribute name from the specified reader.
      Parameters:
      r - The reader.
      encoded - Whether the attribute is encoded.
      Returns:
      The parsed attribute name.
      Throws:
      IOException - Exception thrown by underlying stream.
      ParseException - Attribute name was malformed.
    • parseString

      protected final String parseString(UonReader r, boolean isUrlParamValue) throws IOException, ParseException
      Parses a string value from the specified reader.
      Parameters:
      r - The input reader.
      isUrlParamValue - Whether this is a URL parameter.
      Returns:
      The parsed string.
      Throws:
      IOException - Exception thrown by underlying stream.
      ParseException - Malformed input found.
    • getUonReader

      public final UonReader getUonReader(ParserPipe pipe, boolean decodeChars) throws IOException
      Creates a UonReader from the specified parser pipe.
      Parameters:
      pipe - The parser input.
      decodeChars - Whether the reader should automatically decode URL-encoded characters.
      Returns:
      A new UonReader object.
      Throws:
      IOException - Thrown by underlying stream.
    • isDecoding

      protected final boolean isDecoding()
      Decode "%xx" sequences.
      Returns:
      true if URI encoded characters should be decoded, false if they've already been decoded before being passed to this parser.
      See Also:
    • isValidateEnd

      protected final boolean isValidateEnd()
      Validate end.
      Returns:
      true if after parsing a POJO from the input, verifies that the remaining input in the stream consists of only comments or whitespace.
      See Also:
    • properties

      protected JsonMap properties()
      Description copied from class: ContextSession
      Returns the properties on this bean as a map for debugging.
      Overrides:
      properties in class ReaderParserSession
      Returns:
      The properties on this bean as a map for debugging.