Interface XContentParser
-
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
AbstractXContentParser,JsonXContentParser,MapXContentParser,XContentSubParser
public interface XContentParser extends Closeable
Interface for pull - parsingXContentseeXContentTypefor supported types. To obtain an instance of this class use the following pattern:XContentType xContentType = XContentType.JSON; XContentParser parser = xContentType.xContent().createParser( NamedXContentRegistry.EMPTY, ParserField."{\"key\" : \"value\"}");
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classXContentParser.NumberTypestatic classXContentParser.Token
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description byte[]binaryValue()Reads a plain binary value that was written via one of the following methods:XContentBuilder.field(String, byte[], int, int)}XContentBuilder.field(String, byte[])} as well as via theirStringvariants of the separated value methods.booleanbooleanValue()CharBuffercharBuffer()Returns aCharBufferholding UTF-8 bytes.CharBuffercharBufferOrNull()XContentTypecontentType()StringcurrentName()XContentParser.TokencurrentToken()doubledoubleValue()doubledoubleValue(boolean coerce)floatfloatValue()floatfloatValue(boolean coerce)DeprecationHandlergetDeprecationHandler()The callback to notify when parsing encounters a deprecated field.XContentLocationgetTokenLocation()Used for error reporting to highlight where syntax errors occur in content being parsed.NamedXContentRegistrygetXContentRegistry()The registry used to resolvenamedObject(Class, String, Object).booleanhasTextCharacters()Method that can be used to determine whether calling of textCharacters() would be the most efficient way to access textual content for the event parser currently points to.intintValue()intintValue(boolean coerce)booleanisBooleanValue()booleanisClosed()List<Object>list()List<Object>listOrderedMap()longlongValue()longlongValue(boolean coerce)Map<String,Object>map()<T> Map<String,T>map(Supplier<Map<String,T>> mapFactory, CheckedFunction<XContentParser,T,IOException> mapValueParser)Returns an instance ofMapholding parsed map.Map<String,Object>mapOrdered()Map<String,String>mapStrings()<T> TnamedObject(Class<T> categoryClass, String name, Object context)Parse an object by name.XContentParser.TokennextToken()XContentParser.NumberTypenumberType()NumbernumberValue()ObjectobjectBytes()ObjectobjectText()shortshortValue()shortshortValue(boolean coerce)voidskipChildren()Stringtext()char[]textCharacters()inttextLength()inttextOffset()StringtextOrNull()
-
-
-
Method Detail
-
contentType
XContentType contentType()
-
nextToken
XContentParser.Token nextToken() throws IOException
- Throws:
IOException
-
skipChildren
void skipChildren() throws IOException- Throws:
IOException
-
currentToken
XContentParser.Token currentToken()
-
currentName
String currentName() throws IOException
- Throws:
IOException
-
map
Map<String,Object> map() throws IOException
- Throws:
IOException
-
mapOrdered
Map<String,Object> mapOrdered() throws IOException
- Throws:
IOException
-
mapStrings
Map<String,String> mapStrings() throws IOException
- Throws:
IOException
-
map
<T> Map<String,T> map(Supplier<Map<String,T>> mapFactory, CheckedFunction<XContentParser,T,IOException> mapValueParser) throws IOException
Returns an instance ofMapholding parsed map. Serves as a replacement for the "map", "mapOrdered" and "mapStrings" methods above.- Type Parameters:
T- map value type- Parameters:
mapFactory- factory for creating newMapobjectsmapValueParser- parser for parsing a single map value- Returns:
Mapobject- Throws:
IOException
-
list
List<Object> list() throws IOException
- Throws:
IOException
-
listOrderedMap
List<Object> listOrderedMap() throws IOException
- Throws:
IOException
-
text
String text() throws IOException
- Throws:
IOException
-
textOrNull
String textOrNull() throws IOException
- Throws:
IOException
-
charBufferOrNull
CharBuffer charBufferOrNull() throws IOException
- Throws:
IOException
-
charBuffer
CharBuffer charBuffer() throws IOException
Returns aCharBufferholding UTF-8 bytes. This method should be used to read text only binary content should be read throughbinaryValue()- Throws:
IOException
-
objectText
Object objectText() throws IOException
- Throws:
IOException
-
objectBytes
Object objectBytes() throws IOException
- Throws:
IOException
-
hasTextCharacters
boolean hasTextCharacters()
Method that can be used to determine whether calling of textCharacters() would be the most efficient way to access textual content for the event parser currently points to. Default implementation simply returns false since only actual implementation class has knowledge of its internal buffering state. This method shouldn't be used to check if the token contains text or not.
-
textCharacters
char[] textCharacters() throws IOException- Throws:
IOException
-
textLength
int textLength() throws IOException- Throws:
IOException
-
textOffset
int textOffset() throws IOException- Throws:
IOException
-
numberValue
Number numberValue() throws IOException
- Throws:
IOException
-
numberType
XContentParser.NumberType numberType() throws IOException
- Throws:
IOException
-
shortValue
short shortValue(boolean coerce) throws IOException- Throws:
IOException
-
intValue
int intValue(boolean coerce) throws IOException- Throws:
IOException
-
longValue
long longValue(boolean coerce) throws IOException- Throws:
IOException
-
floatValue
float floatValue(boolean coerce) throws IOException- Throws:
IOException
-
doubleValue
double doubleValue(boolean coerce) throws IOException- Throws:
IOException
-
shortValue
short shortValue() throws IOException- Throws:
IOException
-
intValue
int intValue() throws IOException- Throws:
IOException
-
longValue
long longValue() throws IOException- Throws:
IOException
-
floatValue
float floatValue() throws IOException- Throws:
IOException
-
doubleValue
double doubleValue() throws IOException- Throws:
IOException
-
isBooleanValue
boolean isBooleanValue() throws IOException- Returns:
- true iff the current value is either boolean (
trueorfalse) or one of "false", "true". - Throws:
IOException
-
booleanValue
boolean booleanValue() throws IOException- Throws:
IOException
-
binaryValue
byte[] binaryValue() throws IOExceptionReads a plain binary value that was written via one of the following methods: as well as via theirStringvariants of the separated value methods. Note: Do not use this method to read values written with: these methods write UTF-8 encoded strings and must be read through:text()()}textOrNull()()}textCharacters()()}}
- Throws:
IOException
-
getTokenLocation
XContentLocation getTokenLocation()
Used for error reporting to highlight where syntax errors occur in content being parsed.- Returns:
- last token's location or null if cannot be determined
-
namedObject
<T> T namedObject(Class<T> categoryClass, String name, Object context) throws IOException
Parse an object by name.- Throws:
IOException
-
getXContentRegistry
NamedXContentRegistry getXContentRegistry()
The registry used to resolvenamedObject(Class, String, Object). Use this when building a sub-parser from this parser.
-
isClosed
boolean isClosed()
-
getDeprecationHandler
DeprecationHandler getDeprecationHandler()
The callback to notify when parsing encounters a deprecated field.
-
-