Java Code Examples for org.elasticsearch.common.xcontent.XContentParser#NumberType

The following examples show how to use org.elasticsearch.common.xcontent.XContentParser#NumberType . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractXContentParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
static Object readValue(XContentParser parser, MapFactory mapFactory, XContentParser.Token token) throws IOException {
    if (token == XContentParser.Token.VALUE_NULL) {
        return null;
    } else if (token == XContentParser.Token.VALUE_STRING) {
        return parser.text();
    } else if (token == XContentParser.Token.VALUE_NUMBER) {
        XContentParser.NumberType numberType = parser.numberType();
        if (numberType == XContentParser.NumberType.INT) {
            return parser.intValue();
        } else if (numberType == XContentParser.NumberType.LONG) {
            return parser.longValue();
        } else if (numberType == XContentParser.NumberType.FLOAT) {
            return parser.floatValue();
        } else if (numberType == XContentParser.NumberType.DOUBLE) {
            return parser.doubleValue();
        }
    } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
        return parser.booleanValue();
    } else if (token == XContentParser.Token.START_OBJECT) {
        return readMap(parser, mapFactory);
    } else if (token == XContentParser.Token.START_ARRAY) {
        return readList(parser, mapFactory);
    } else if (token == XContentParser.Token.VALUE_EMBEDDED_OBJECT) {
        return parser.binaryValue();
    }
    return null;
}
 
Example 2
Source File: XmlXContentParser.java    From elasticsearch-xml with Apache License 2.0 4 votes vote down vote up
@Override
public XContentParser.NumberType numberType() throws IOException {
    return convertNumberType(parser.getNumberType());
}