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

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

Introduction

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

Prototype

public String nextTextValue() throws IOException, JsonParseException 

Source Link

Document

Method that fetches next token (as if calling #nextToken ) and if it is JsonToken#VALUE_STRING returns contained String value; otherwise returns null.

Usage

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

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

    final ReturnTypeImpl returnType = new ReturnTypeImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Type".equals(jp.getCurrentName())) {
                returnType.setType(jp.nextTextValue());
            } else if ("Nullable".equals(jp.getCurrentName())) {
                returnType.setNullable(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("MaxLength".equals(jp.getCurrentName())) {
                final String maxLenght = jp.nextTextValue();
                returnType.setMaxLength(
                        maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght));
            } else if ("Precision".equals(jp.getCurrentName())) {
                returnType.setPrecision(Integer.valueOf(jp.nextTextValue()));
            } else if ("Scale".equals(jp.getCurrentName())) {
                final String scale = jp.nextTextValue();
                returnType.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale));
            } else if ("SRID".equals(jp.getCurrentName())) {
                final String srid = jp.nextTextValue();
                if (srid != null) {
                    returnType.setSrid(SRID.valueOf(srid));
                }/*from www  .  j av a2s  .c  om*/
            }
        }
    }

    return returnType;
}

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

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

    final TermImpl term = new TermImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                term.setName(jp.nextTextValue());
            } else if ("Type".equals(jp.getCurrentName())) {
                term.setType(jp.nextTextValue());
            } else if ("BaseTerm".equals(jp.getCurrentName())) {
                term.setBaseTerm(jp.nextTextValue());
            } else if ("DefaultValue".equals(jp.getCurrentName())) {
                term.setDefaultValue(jp.nextTextValue());
            } else if ("Nullable".equals(jp.getCurrentName())) {
                term.setNullable(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("MaxLength".equals(jp.getCurrentName())) {
                final String maxLenght = jp.nextTextValue();
                term.setMaxLength(/*  w  w  w . ja v a  2s  .co  m*/
                        maxLenght.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.valueOf(maxLenght));
            } else if ("Precision".equals(jp.getCurrentName())) {
                term.setPrecision(Integer.valueOf(jp.nextTextValue()));
            } else if ("Scale".equals(jp.getCurrentName())) {
                final String scale = jp.nextTextValue();
                term.setScale(scale.equalsIgnoreCase("variable") ? 0 : Integer.valueOf(scale));
            } else if ("SRID".equals(jp.getCurrentName())) {
                final String srid = jp.nextTextValue();
                if (srid != null) {
                    term.setSrid(SRID.valueOf(srid));
                }
            } else if ("AppliesTo".equals(jp.getCurrentName())) {
                term.getAppliesTo().addAll(Arrays.asList(StringUtils.split(jp.nextTextValue())));
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                term.getAnnotations().add(jp.readValueAs(AnnotationImpl.class));
            }
        }
    }

    return term;
}

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));
                }// w w w .j a va  2 s.  c  o  m
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                typeDefinition.getAnnotations().add(jp.readValueAs(AnnotationImpl.class));
            }
        }
    }

    return typeDefinition;
}

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

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

    final FunctionImportImpl funcImp = new FunctionImportImpl();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                funcImp.setName(jp.nextTextValue());
            } else if ("ReturnType".equals(jp.getCurrentName())) {
                funcImp.setReturnType(jp.nextTextValue());
            } else if ("EntitySet".equals(jp.getCurrentName())) {
                funcImp.setEntitySet(jp.nextTextValue());
            } else if ("EntitySetPath".equals(jp.getCurrentName())) {
                funcImp.setEntitySetPath(jp.nextTextValue());
            } else if ("IsComposable".equals(jp.getCurrentName())) {
                funcImp.setComposable(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("IsSideEffecting".equals(jp.getCurrentName())) {
                funcImp.setSideEffecting(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("IsBindable".equals(jp.getCurrentName())) {
                funcImp.setBindable(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("IsAlwaysBindable".equals(jp.getCurrentName())) {
                funcImp.setAlwaysBindable(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("HttpMethod".equals(jp.getCurrentName())) {
                funcImp.setHttpMethod(jp.nextTextValue());
            } else if ("Parameter".equals(jp.getCurrentName())) {
                jp.nextToken();//from   ww  w  .  j a v a 2  s  .c o m
                funcImp.getParameters().add(jp.readValueAs(ParameterImpl.class));
            }
        }
    }

    return funcImp;
}

From source file:org.apache.olingo.client.core.edm.xml.v4.annotation.DynExprConstructDeserializer.java

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

    DynExprConstructImpl construct = null;

    if (DynExprSingleParamOp.Type.fromString(jp.getCurrentName()) != null) {
        final DynExprSingleParamOp dynExprSingleParamOp = new DynExprSingleParamOp();
        dynExprSingleParamOp.setType(DynExprSingleParamOp.Type.fromString(jp.getCurrentName()));

        jp.nextToken();//from  w w  w.j  av a2s  . c  o  m
        jp.nextToken();
        dynExprSingleParamOp.setExpression(jp.readValueAs(DynExprConstructImpl.class));

        construct = dynExprSingleParamOp;
    } else if (DynExprDoubleParamOp.Type.fromString(jp.getCurrentName()) != null) {
        final DynExprDoubleParamOp dynExprDoubleParamOp = new DynExprDoubleParamOp();
        dynExprDoubleParamOp.setType(DynExprDoubleParamOp.Type.fromString(jp.getCurrentName()));

        jp.nextToken();
        jp.nextToken();
        dynExprDoubleParamOp.setLeft(jp.readValueAs(DynExprConstructImpl.class));
        dynExprDoubleParamOp.setRight(jp.readValueAs(DynExprConstructImpl.class));

        construct = dynExprDoubleParamOp;
    } else if (ArrayUtils.contains(EL_OR_ATTR, jp.getCurrentName())) {
        final AbstractElOrAttrConstruct elOrAttr = getElOrAttrInstance(jp.getCurrentName());
        elOrAttr.setValue(jp.nextTextValue());

        construct = elOrAttr;
    } else if (APPLY.equals(jp.getCurrentName())) {
        jp.nextToken();
        construct = jp.readValueAs(Apply.class);
    } else if (CAST.equals(jp.getCurrentName())) {
        jp.nextToken();
        construct = jp.readValueAs(Cast.class);
    } else if (COLLECTION.equals(jp.getCurrentName())) {
        jp.nextToken();
        construct = jp.readValueAs(Collection.class);
    } else if (IF.equals(jp.getCurrentName())) {
        jp.nextToken();
        jp.nextToken();

        final If _if = new If();
        _if.setGuard(parseConstOrEnumExprConstruct(jp));
        _if.setThen(parseConstOrEnumExprConstruct(jp));
        _if.setElse(parseConstOrEnumExprConstruct(jp));

        construct = _if;
    } else if (IS_OF.equals(jp.getCurrentName())) {
        jp.nextToken();
        construct = jp.readValueAs(IsOf.class);
    } else if (LABELED_ELEMENT.equals(jp.getCurrentName())) {
        jp.nextToken();
        construct = jp.readValueAs(LabeledElement.class);
    } else if (NULL.equals(jp.getCurrentName())) {
        jp.nextToken();
        construct = jp.readValueAs(Null.class);
    } else if (RECORD.equals(jp.getCurrentName())) {
        jp.nextToken();
        construct = jp.readValueAs(Record.class);
    } else if (URL_REF.equals(jp.getCurrentName())) {
        jp.nextToken();
        construct = jp.readValueAs(UrlRef.class);
    }

    return construct;
}

From source file:ren.hankai.cordwood.jackson.DateDeserializerTest.java

@Test
public void testDeserialize() throws Exception {
    final ObjectMapper om = new ObjectMapper();
    final DateDeserializer des = new DateDeserializer();
    final JsonParser jp = om.getFactory().createParser("{\"date\": \"2018-09-01\"}");

    String val = null;
    do {/*from w w w. ja  va 2  s  . c  o m*/
        val = jp.nextTextValue();
    } while (val == null);

    final Date date = des.deserialize(jp, om.getDeserializationContext());
    final Date expDate = DateUtils.parseDate(jp.getText(), "yyyy-MM-dd");
    Assert.assertTrue(DateUtils.isSameDay(date, expDate));
}

From source file:ren.hankai.cordwood.jackson.DateDeserializerTest.java

@Test
public void testDeserializeWithCustomFormat() throws Exception {
    final ObjectMapper om = new ObjectMapper();
    final DateDeserializer des = new DateDeserializer("yyyy|MM|dd");
    final JsonParser jp = om.getFactory().createParser("{\"date\": \"2018|09|01\"}");

    String val = null;
    do {//  w ww.  j  a v a  2  s  . co m
        val = jp.nextTextValue();
    } while (val == null);

    final Date date = des.deserialize(jp, om.getDeserializationContext());
    final Date expDate = DateUtils.parseDate(jp.getText(), "yyyy|MM|dd");
    Assert.assertTrue(DateUtils.isSameDay(date, expDate));
}

From source file:ren.hankai.cordwood.jackson.DateDeserializerTest.java

@Test
public void testDeserializeInvalidDate() throws Exception {
    final ObjectMapper om = new ObjectMapper();
    final DateDeserializer des = new DateDeserializer();
    final JsonParser jp = om.getFactory().createParser("{\"date\": \"20180901\"}");

    String val = null;
    do {/*from   w  w w .  j  a va2  s  .  co m*/
        val = jp.nextTextValue();
    } while (val == null);

    final Date date = des.deserialize(jp, om.getDeserializationContext());
    Assert.assertNull(date);
}

From source file:ren.hankai.cordwood.jackson.DateTimeDeserializerTest.java

@Test
public void testDeserialize() throws Exception {
    final ObjectMapper om = new ObjectMapper();
    final DateTimeDeserializer des = new DateTimeDeserializer();
    final JsonParser jp = om.getFactory().createParser("{\"date\": \"2018-09-01 13:23:12\"}");

    String val = null;
    do {//from  w ww .  ja va 2  s .  c  o  m
        val = jp.nextTextValue();
    } while (val == null);

    final Date date = des.deserialize(jp, om.getDeserializationContext());
    final Date expDate = DateUtils.parseDate(jp.getText(), "yyyy-MM-dd HH:mm:ss");
    Assert.assertTrue(DateUtils.truncatedEquals(date, expDate, Calendar.SECOND));
}

From source file:ren.hankai.cordwood.jackson.DateTimeDeserializerTest.java

@Test
public void testDeserializeWithCustomFormat() throws Exception {
    final ObjectMapper om = new ObjectMapper();
    final DateTimeDeserializer des = new DateTimeDeserializer("yyyy|MM|dd HH|mm|ss");
    final JsonParser jp = om.getFactory().createParser("{\"date\": \"2018|09|01 13|23|12\"}");

    String val = null;
    do {/*from ww w  . ja v a2s  .c o m*/
        val = jp.nextTextValue();
    } while (val == null);

    final Date date = des.deserialize(jp, om.getDeserializationContext());
    final Date expDate = DateUtils.parseDate(jp.getText(), "yyyy|MM|dd HH|mm|ss");
    Assert.assertTrue(DateUtils.truncatedEquals(date, expDate, Calendar.SECOND));
}