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

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

Introduction

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

Prototype

public abstract JsonToken getCurrentToken();

Source Link

Document

Accessor to find which token parser currently points to, if any; null will be returned if none.

Usage

From source file:com.msopentech.odatajclient.engine.data.metadata.edm.v4.FunctionDeserializer.java

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

    final Function function = new Function();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                function.setName(jp.nextTextValue());
            } else if ("IsBound".equals(jp.getCurrentName())) {
                function.setBound(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("IsComposable".equals(jp.getCurrentName())) {
                function.setComposable(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("EntitySetPath".equals(jp.getCurrentName())) {
                function.setEntitySetPath(jp.nextTextValue());
            } else if ("Parameter".equals(jp.getCurrentName())) {
                jp.nextToken();//from  w  w  w  . ja  va  2s. com
                function.getParameters().add(jp.getCodec().readValue(jp, Parameter.class));
            } else if ("ReturnType".equals(jp.getCurrentName())) {
                function.setReturnType(parseReturnType(jp, "Function"));
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                function.setAnnotation(jp.getCodec().readValue(jp, Annotation.class));
            }
        }
    }

    return function;
}

From source file:org.intelligentsia.dowsers.core.serializers.jackson.ClassInformationDeserializer.java

@Override
public ClassInformation deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    String description = null;/*from  ww w.j  av  a2  s  .c o m*/

    if (jp.hasCurrentToken()) {
        if (jp.getCurrentToken().equals(JsonToken.START_OBJECT)) {
            jp.nextValue();
            description = jp.getText();
            jp.nextToken();
        }
    }

    return description != null ? ClassInformation.parse(description) : null;
}

From source file:com.msopentech.odatajclient.engine.data.metadata.edm.v4.TermDeserializer.java

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

    final Term term = new Term();

    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())) {
                term.setMaxLength(jp.nextTextValue());
            } else if ("Precision".equals(jp.getCurrentName())) {
                term.setPrecision(BigInteger.valueOf(jp.nextLongValue(0L)));
            } else if ("Scale".equals(jp.getCurrentName())) {
                term.setScale(BigInteger.valueOf(jp.nextLongValue(0L)));
            } else if ("SRID".equals(jp.getCurrentName())) {
                term.setSrid(jp.nextTextValue());
            } else if ("AppliesTo".equals(jp.getCurrentName())) {
                for (String split : StringUtils.split(jp.nextTextValue())) {
                    term.getAppliesTo().add(CSDLElement.valueOf(split));
                }//  www .  ja v a 2 s .c o m
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                term.setAnnotation(jp.getCodec().readValue(jp, Annotation.class));
            }
        }
    }

    return term;
}

From source file:org.agorava.linkedin.jackson.ConnectionAuthorizationDeserializer.java

@Override
public ConnectionAuthorization deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectMapper mapper = BeanResolver.getInstance().resolve(ObjectMapper.class);
    if (jp.hasCurrentToken() && jp.getCurrentToken().equals(JsonToken.START_OBJECT)) {
        JsonNode dataNode = jp.readValueAs(JsonNode.class).get("headers").get("values").get(0);
        if (dataNode != null) {
            return mapper.reader(new TypeReference<ConnectionAuthorization>() {
            }).readValue(dataNode);//from www .j a va 2  s .c  o m
        }
    }
    throw ctxt.mappingException("Expected JSON object");
}

From source file:com.msopentech.odatajclient.engine.data.metadata.edm.ReferentialConstraintRoleDeserializer.java

@Override
public ReferentialConstraintRole deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    final ReferentialConstraintRole refConstRole = new ReferentialConstraintRole();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Role".equals(jp.getCurrentName())) {
                refConstRole.setRole(jp.nextTextValue());
            } else if ("PropertyRef".equals(jp.getCurrentName())) {
                jp.nextToken();/*  w w w. jav  a2 s  .com*/
                refConstRole.getPropertyRefs().add(jp.getCodec().readValue(jp, PropertyRef.class));
            }
        }
    }

    return refConstRole;
}

From source file:com.kaaprotech.satu.jackson.SatuDeserializers.java

@Override
public JsonDeserializer<?> findMapDeserializer(final MapType type, final DeserializationConfig config,
        BeanDescription beanDesc, final KeyDeserializer keyDeserializer,
        final TypeDeserializer elementTypeDeserializer, final JsonDeserializer<?> elementDeserializer)
        throws JsonMappingException {

    if (ImmutableMap.class.isAssignableFrom(type.getRawClass())) {
        return new StdDeserializer<Object>(type) {
            private static final long serialVersionUID = 1L;

            @Override/* w  w w .  j ava2  s . c  o m*/
            public Object deserialize(JsonParser jp, DeserializationContext context) throws IOException {

                JsonToken t = jp.getCurrentToken();
                if (t == JsonToken.START_OBJECT) {
                    t = jp.nextToken();
                }
                if (t != JsonToken.FIELD_NAME && t != JsonToken.END_OBJECT) {
                    throw context.mappingException(type.getRawClass());
                }

                MutableMap<Object, Object> m = Maps.mutable.of();

                for (; jp.getCurrentToken() == JsonToken.FIELD_NAME; jp.nextToken()) {
                    // Pointing to field name
                    String fieldName = jp.getCurrentName();
                    Object key = (keyDeserializer == null) ? fieldName
                            : keyDeserializer.deserializeKey(fieldName, context);
                    t = jp.nextToken();

                    Object value;
                    if (t == JsonToken.VALUE_NULL) {
                        value = null;
                    } else if (elementDeserializer == null) {
                        value = jp.readValueAs(type.getContentType().getRawClass());
                    } else if (elementTypeDeserializer == null) {
                        value = elementDeserializer.deserialize(jp, context);
                    } else {
                        value = elementDeserializer.deserializeWithType(jp, context, elementTypeDeserializer);
                    }
                    m.put(key, value);
                }
                return m.toImmutable();
            }
        };
    }

    return super.findMapDeserializer(type, config, beanDesc, keyDeserializer, elementTypeDeserializer,
            elementDeserializer);
}

From source file:com.msopentech.odatajclient.engine.data.metadata.edm.SchemaDeserializer.java

@Override
public Schema deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    final Schema schema = new Schema();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Namespace".equals(jp.getCurrentName())) {
                schema.setNamespace(jp.nextTextValue());
            } else if ("Alias".equals(jp.getCurrentName())) {
                schema.setAlias(jp.nextTextValue());
            } else if ("Using".equals(jp.getCurrentName())) {
                jp.nextToken();/*from w  ww .  j  a  va  2s .c  o  m*/
                schema.getUsings().add(jp.getCodec().readValue(jp, Using.class));
            } else if ("Association".equals(jp.getCurrentName())) {
                jp.nextToken();
                schema.getAssociations().add(jp.getCodec().readValue(jp, Association.class));
            } else if ("ComplexType".equals(jp.getCurrentName())) {
                jp.nextToken();
                schema.getComplexTypes().add(jp.getCodec().readValue(jp, ComplexType.class));
            } else if ("EntityType".equals(jp.getCurrentName())) {
                jp.nextToken();
                schema.getEntityTypes().add(jp.getCodec().readValue(jp, EntityType.class));
            } else if ("EnumType".equals(jp.getCurrentName())) {
                jp.nextToken();
                schema.getEnumTypes().add(jp.getCodec().readValue(jp, EnumType.class));
            } else if ("ValueTerm".equals(jp.getCurrentName())) {
                jp.nextToken();
                schema.getValueTerms().add(jp.getCodec().readValue(jp, ValueTerm.class));
            } else if ("EntityContainer".equals(jp.getCurrentName())) {
                jp.nextToken();
                schema.getEntityContainers().add(jp.getCodec().readValue(jp, EntityContainer.class));
            } else if ("Annotations".equals(jp.getCurrentName())) {
                jp.nextToken();
                schema.getAnnotations().add(jp.getCodec().readValue(jp, Annotations.class));
            }
        }
    }

    return schema;
}

From source file:org.emfjson.jackson.databind.deser.EMapDeserializer.java

@Override
@SuppressWarnings("unchecked")
public EList<Map.Entry<?, ?>> deserialize(JsonParser jp, DeserializationContext ctxt,
        EList<Map.Entry<?, ?>> intoValue) throws IOException {
    final EReference reference = EMFContext.getReference(ctxt);

    if (jp.getCurrentToken() == JsonToken.START_OBJECT) {

        while (jp.nextToken() != JsonToken.END_OBJECT) {
            final String key = jp.getCurrentName();
            jp.nextToken();/* ww  w  .j  a va 2  s  .c o m*/

            final Object value;
            if (jp.getCurrentToken() == JsonToken.START_OBJECT) {
                value = ctxt.readValue(jp, EObject.class);
            } else {
                value = ctxt.readValue(jp, Object.class);
            }

            // Dynamic objects do not use the EMap interface
            // but store entries in a DynamicEList instead.
            if (intoValue instanceof EMap) {
                ((EMap) intoValue).put(key, value);
            } else if (reference != null) {
                intoValue
                        .add((Map.Entry<?, ?>) EObjects.createEntry(key, value, reference.getEReferenceType()));
            }
        }
    }

    return intoValue;
}

From source file:com.cedarsoft.serialization.jackson.ListSerializer.java

@Nullable
protected Object deserializeElement(@Nonnull JsonParser deserializeFrom, int index) throws IOException {
    //noinspection EnumSwitchStatementWhichMissesCases
    switch (deserializeFrom.getCurrentToken()) {
    case VALUE_STRING:
        return deserializeFrom.getText();
    case VALUE_NUMBER_INT:
        return deserializeFrom.getIntValue();
    case VALUE_NUMBER_FLOAT:
        return deserializeFrom.getDoubleValue();
    case VALUE_TRUE:
        return true;
    case VALUE_FALSE:
        return false;
    case VALUE_NULL:
        return null;
    }//from  w  ww .  j  av  a 2 s  .  c  o  m

    return deserializeFrom.getText();
}

From source file:com.msopentech.odatajclient.engine.data.metadata.edm.FunctionImportDeserializer.java

@Override
public FunctionImport deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    final FunctionImport funcImp = new FunctionImport();

    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(Boolean.valueOf(jp.nextTextValue()));
            } else if ("IsSideEffecting".equals(jp.getCurrentName())) {
                funcImp.setSideEffecting(Boolean.valueOf(jp.nextTextValue()));
            } else if ("IsBindable".equals(jp.getCurrentName())) {
                funcImp.setBindable(Boolean.valueOf(jp.nextTextValue()));
            } else if ("IsAlwaysBindable".equals(jp.getCurrentName())) {
                funcImp.setAlwaysBindable(Boolean.valueOf(jp.nextTextValue()));
            } else if ("HttpMethod".equals(jp.getCurrentName())) {
                funcImp.setHttpMethod(jp.nextTextValue());
            } else if ("Parameter".equals(jp.getCurrentName())) {
                jp.nextToken();//from ww w.ja va  2  s  .  c o  m
                funcImp.getParameters().add(jp.getCodec().readValue(jp, Parameter.class));
            }
        }
    }

    return funcImp;
}