Example usage for com.fasterxml.jackson.core JsonParser nextIntValue

List of usage examples for com.fasterxml.jackson.core JsonParser nextIntValue

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonParser nextIntValue.

Prototype

public int nextIntValue(int defaultValue) throws IOException, JsonParseException 

Source Link

Document

Method that fetches next token (as if calling #nextToken ) and if it is JsonToken#VALUE_NUMBER_INT returns 32-bit int value; otherwise returns specified default value It is functionally equivalent to:
 return (nextToken() == JsonToken.VALUE_NUMBER_INT) ? 

Usage

From source file:org.apache.olingo.client.core.edm.xml.TypeDefinitionDeserializer.java

@Override
protected TypeDefinitionImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    final TypeDefinitionImpl typeDefinition = new TypeDefinitionImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                typeDefinition.setName(jp.nextTextValue());
            } else if ("UnderlyingType".equals(jp.getCurrentName())) {
                typeDefinition.setUnderlyingType(jp.nextTextValue());
            } else if ("MaxLength".equals(jp.getCurrentName())) {
                typeDefinition.setMaxLength(jp.nextIntValue(0));
            } else if ("Unicode".equals(jp.getCurrentName())) {
                typeDefinition.setUnicode(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("Precision".equals(jp.getCurrentName())) {
                typeDefinition.setPrecision(jp.nextIntValue(0));
            } else if ("Scale".equals(jp.getCurrentName())) {
                final String scale = jp.nextTextValue();
                typeDefinition.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale));
            } else if ("SRID".equals(jp.getCurrentName())) {
                final String srid = jp.nextTextValue();
                if (srid != null) {
                    typeDefinition.setSrid(SRID.valueOf(srid));
                }/*from   w ww  . j  ava 2s. com*/
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                typeDefinition.getAnnotations().add(jp.readValueAs(AnnotationImpl.class));
            }
        }
    }

    return typeDefinition;
}