Class AbstractObjectParser<Value,​Context>

All Implemented Interfaces:
java.util.function.BiFunction<XContentParser,​Context,​Value>, ContextParser<Context,​Value>
Direct Known Subclasses:
ConstructingObjectParser, ObjectParser

public abstract class AbstractObjectParser<Value,​Context>
extends java.lang.Object
implements java.util.function.BiFunction<XContentParser,​Context,​Value>, ContextParser<Context,​Value>
Superclass for ObjectParser and ConstructingObjectParser. Defines most of the "declare" methods so they can be shared.
  • Constructor Details

  • Method Details

    • declareField

      public abstract <T> void declareField​(java.util.function.BiConsumer<Value,​T> consumer, ContextParser<Context,​T> parser, ParseField parseField, ObjectParser.ValueType type)
      Declare some field. Usually it is easier to use declareString(BiConsumer, ParseField) or declareObject(BiConsumer, ContextParser, ParseField) rather than call this directly.
    • declareNamedObjects

      public abstract <T> void declareNamedObjects​(java.util.function.BiConsumer<Value,​java.util.List<T>> consumer, ObjectParser.NamedObjectParser<T,​Context> namedObjectParser, ParseField parseField)
      Declares named objects in the style of aggregations. These are named inside and object like this:
         "aggregations": {
           "name_1": { "aggregation_type": {} },
           "name_2": { "aggregation_type": {} },
           "name_3": { "aggregation_type": {} }
      Unlike the other version of this method, "ordered" mode (arrays of objects) is not supported. See NamedObjectHolder in ObjectParserTests for examples of how to invoke this.
      consumer - sets the values once they have been parsed
      namedObjectParser - parses each named object
      parseField - the field to parse
    • declareNamedObjects

      public abstract <T> void declareNamedObjects​(java.util.function.BiConsumer<Value,​java.util.List<T>> consumer, ObjectParser.NamedObjectParser<T,​Context> namedObjectParser, java.util.function.Consumer<Value> orderedModeCallback, ParseField parseField)
      Declares named objects in the style of highlighting's field element. These are usually named inside and object like this:
         "highlight": {
           "fields": {        <------ this one
             "title": {},
             "body": {},
             "category": {}
      but, when order is important, some may be written this way:
         "highlight": {
           "fields": [        <------ this one
             {"title": {}},
             {"body": {}},
             {"category": {}}
      This is because json doesn't enforce ordering. Elasticsearch reads it in the order sent but tools that generate json are free to put object members in an unordered Map, jumbling them. Thus, if you care about order you can send the object in the second way. See NamedObjectHolder in ObjectParserTests for examples of how to invoke this.
      consumer - sets the values once they have been parsed
      namedObjectParser - parses each named object
      orderedModeCallback - called when the named object is parsed using the "ordered" mode (the array of objects)
      parseField - the field to parse
    • getName

      public abstract java.lang.String getName()
    • declareField

      public <T> void declareField​(java.util.function.BiConsumer<Value,​T> consumer, CheckedFunction<XContentParser,​T,​> parser, ParseField parseField, ObjectParser.ValueType type)
    • declareObject

      public <T> void declareObject​(java.util.function.BiConsumer<Value,​T> consumer, ContextParser<Context,​T> objectParser, ParseField field)
    • declareFloat

      public void declareFloat​(java.util.function.BiConsumer<Value,​java.lang.Float> consumer, ParseField field)
    • declareDouble

      public void declareDouble​(java.util.function.BiConsumer<Value,​java.lang.Double> consumer, ParseField field)
    • declareLong

      public void declareLong​(java.util.function.BiConsumer<Value,​java.lang.Long> consumer, ParseField field)
    • declareInt

      public void declareInt​(java.util.function.BiConsumer<Value,​java.lang.Integer> consumer, ParseField field)
    • declareString

      public void declareString​(java.util.function.BiConsumer<Value,​java.lang.String> consumer, ParseField field)
    • declareStringOrNull

      public void declareStringOrNull​(java.util.function.BiConsumer<Value,​java.lang.String> consumer, ParseField field)
    • declareBoolean

      public void declareBoolean​(java.util.function.BiConsumer<Value,​java.lang.Boolean> consumer, ParseField field)
    • declareObjectArray

      public <T> void declareObjectArray​(java.util.function.BiConsumer<Value,​java.util.List<T>> consumer, ContextParser<Context,​T> objectParser, ParseField field)
    • declareStringArray

      public void declareStringArray​(java.util.function.BiConsumer<Value,​java.util.List<java.lang.String>> consumer, ParseField field)
    • declareDoubleArray

      public void declareDoubleArray​(java.util.function.BiConsumer<Value,​java.util.List<java.lang.Double>> consumer, ParseField field)
    • declareFloatArray

      public void declareFloatArray​(java.util.function.BiConsumer<Value,​java.util.List<java.lang.Float>> consumer, ParseField field)
    • declareLongArray

      public void declareLongArray​(java.util.function.BiConsumer<Value,​java.util.List<java.lang.Long>> consumer, ParseField field)
    • declareIntArray

      public void declareIntArray​(java.util.function.BiConsumer<Value,​java.util.List<java.lang.Integer>> consumer, ParseField field)
    • declareFieldArray

      public <T> void declareFieldArray​(java.util.function.BiConsumer<Value,​java.util.List<T>> consumer, ContextParser<Context,​T> itemParser, ParseField field, ObjectParser.ValueType type)
      Declares a field that can contain an array of elements listed in the type ValueType enum