Class FieldParserFactory


public class FieldParserFactory extends Object
Creates a field parser given a field description and an optional field listener.

Parse position: { ... field : ^ ? for a newly-seen field. Constructs a value parser and its listeners by looking ahead some number of tokens to "sniff" the type of the value. For example:

  • foo: <value> - Field value
  • foo: [ <value> ] - 1D array value
  • foo: [ [<value> ] ] - 2D array value
  • Etc.

There are two cases in which no type estimation is possible:

ValueDefFactory handles syntactic type inference. The associated listener enforces semantic rules. For example, if a schema is available, and we know that field "x" must be an Integer, but this class reports that it is an object, then the listener should raise an exception.

Also, the parser cannot enforce type consistency. This method looks only at the first appearance of a value: a sample size of one. JSON allows anything. The listener must enforce semantic rules that say whether a different type is allowed for later values.