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

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

Introduction

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

Prototype

public abstract String getCurrentName() throws IOException, JsonParseException;

Source Link

Document

Method that can be called to get the name associated with the current token: for JsonToken#FIELD_NAME s it will be the same as what #getText returns; for field values it will be preceding field name; and for others (array values, root-level values) null.

Usage

From source file:org.gvnix.web.json.DataBinderDeserializer.java

/**
 * Deserializes JSON property into Map<String, String> format to use it in a
 * Spring {@link DataBinder}.//ww  w  .jav  a  2s .c  o m
 * <p/>
 * Check token's type to perform an action:
 * <ul>
 * <li>If it's a property, stores it in map</li>
 * <li>If it's an object, calls to
 * {@link #readObject(JsonParser, DeserializationContext, String)}</li>
 * <li>If it's an array, calls to
 * {@link #readArray(JsonParser, DeserializationContext, String)}</li>
 * </ul>
 * 
 * @param parser
 * @param ctxt
 * @param token current token
 * @param prefix property dataBinder path
 * @return
 * @throws IOException
 * @throws JsonProcessingException
 */
protected Map<String, String> readField(JsonParser parser, DeserializationContext ctxt, JsonToken token,
        String prefix) throws IOException, JsonProcessingException {

    String fieldName = null;
    String fieldValue = null;

    // Read the field name
    fieldName = parser.getCurrentName();

    // If current token contains a field name
    if (!isEmptyString(fieldName)) {

        // Append the prefix if given
        if (isEmptyString(prefix)) {
            fieldName = parser.getCurrentName();
        } else {
            fieldName = prefix.concat(parser.getCurrentName());
        }
    }
    // If current token contains mark array or object start markers.
    // Note it cannot be a field value because it will be read below and
    // then the token is advanced to the next
    else {

        // Use the prefix in recursive calls
        if (!isEmptyString(prefix)) {
            fieldName = prefix;
        }
    }

    // If current token has been used to read the field name, advance
    // stream to the next token that contains the field value
    if (token == JsonToken.FIELD_NAME) {
        token = parser.nextToken();
    }

    // Field value
    switch (token) {
    case VALUE_STRING:
    case VALUE_NUMBER_INT:
    case VALUE_NUMBER_FLOAT:
    case VALUE_EMBEDDED_OBJECT:
    case VALUE_TRUE:
    case VALUE_FALSE:
        // Plain field: Store value
        Map<String, String> field = new HashMap<String, String>();
        fieldValue = parser.getText();
        field.put(fieldName, fieldValue);
        return field;
    case START_ARRAY:
        // Read array items
        return readArray(parser, ctxt, fieldName);
    case START_OBJECT:
        // Read object properties
        return readObject(parser, ctxt, fieldName);
    case END_ARRAY:
    case END_OBJECT:
        // Skip array and object end markers
        parser.nextToken();
        break;
    default:
        throw ctxt.mappingException(getBeanClass());
    }
    return Collections.emptyMap();
}

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

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

    final AbstractEntitySet entitySet = ODataVersion.V3 == client.getWorkingVersion()
            ? new com.msopentech.odatajclient.engine.metadata.edm.v3.EntitySet()
            : new com.msopentech.odatajclient.engine.metadata.edm.v4.EntitySet();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                entitySet.setName(jp.nextTextValue());
            } else if ("EntityType".equals(jp.getCurrentName())) {
                entitySet.setEntityType(jp.nextTextValue());
            } else if ("IncludeInServiceDocument".equals(jp.getCurrentName())) {
                ((com.msopentech.odatajclient.engine.metadata.edm.v4.EntitySet) entitySet)
                        .setIncludeInServiceDocument(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("NavigationPropertyBinding".equals(jp.getCurrentName())) {
                jp.nextToken();//from w w  w .jav a2  s  . c  o  m
                ((com.msopentech.odatajclient.engine.metadata.edm.v4.EntitySet) entitySet)
                        .getNavigationPropertyBindings()
                        .add(jp.getCodec().readValue(jp, NavigationPropertyBinding.class));
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((com.msopentech.odatajclient.engine.metadata.edm.v4.EntitySet) entitySet)
                        .setAnnotation(jp.getCodec().readValue(jp, Annotation.class));
            }
        }
    }

    return entitySet;
}

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

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

    final AbstractEnumType enumType = ODataVersion.V3 == client.getWorkingVersion()
            ? new com.msopentech.odatajclient.engine.metadata.edm.v3.EnumType()
            : new com.msopentech.odatajclient.engine.metadata.edm.v4.EnumType();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                enumType.setName(jp.nextTextValue());
            } else if ("UnderlyingType".equals(jp.getCurrentName())) {
                enumType.setUnderlyingType(jp.nextTextValue());
            } else if ("IsFlags".equals(jp.getCurrentName())) {
                enumType.setFlags(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("Member".equals(jp.getCurrentName())) {
                jp.nextToken();//from   ww w.  ja va 2 s . co m
                if (enumType instanceof com.msopentech.odatajclient.engine.metadata.edm.v3.EnumType) {
                    ((com.msopentech.odatajclient.engine.metadata.edm.v3.EnumType) enumType).getMembers()
                            .add(jp.getCodec().readValue(jp,
                                    com.msopentech.odatajclient.engine.metadata.edm.v3.Member.class));
                } else {
                    ((com.msopentech.odatajclient.engine.metadata.edm.v4.EnumType) enumType).getMembers()
                            .add(jp.getCodec().readValue(jp,
                                    com.msopentech.odatajclient.engine.metadata.edm.v4.Member.class));
                }
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((com.msopentech.odatajclient.engine.metadata.edm.v4.EnumType) enumType)
                        .setAnnotation(jp.getCodec().readValue(jp, Annotation.class));
            }
        }
    }

    return enumType;
}

From source file:org.oscim.utils.overpass.OverpassAPIReader.java

private void parseRelation(JsonParser jp) throws JsonParseException, IOException {

    long id = 0;/*www .  ja  v a 2 s  .  c om*/
    TagSet tags = null;
    ArrayList<TmpRelation> members = new ArrayList<TmpRelation>();

    while (jp.nextToken() != JsonToken.END_OBJECT) {

        String name = jp.getCurrentName();
        jp.nextToken();

        if ("id".equals(name))
            id = jp.getLongValue();

        else if ("members".equals(name)) {
            while (jp.nextToken() != JsonToken.END_ARRAY) {
                TmpRelation member = new TmpRelation();

                while (jp.nextToken() != JsonToken.END_OBJECT) {
                    name = jp.getCurrentName();
                    jp.nextToken();

                    if ("type".equals(name))
                        member.type = jp.getText();

                    else if ("ref".equals(name))
                        member.id = Long.valueOf(jp.getLongValue());

                    else if ("role".equals(name))
                        member.role = jp.getText();
                }
                members.add(member);
            }
        } else if ("tags".equals(name))
            tags = parseTags(jp);
    }

    OsmRelation relation = new OsmRelation(tags, id, members.size());
    ownRelations.add(relation);
    relationsById.put(Long.valueOf(id), relation);
    relationMembersForRelation.put(relation, members);
}

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

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

    final AbstractEntitySet entitySet = ODataVersion.V3 == client.getWorkingVersion()
            ? new com.msopentech.odatajclient.engine.data.metadata.edm.v3.EntitySet()
            : new com.msopentech.odatajclient.engine.data.metadata.edm.v4.EntitySet();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                entitySet.setName(jp.nextTextValue());
            } else if ("EntityType".equals(jp.getCurrentName())) {
                entitySet.setEntityType(jp.nextTextValue());
            } else if ("IncludeInServiceDocument".equals(jp.getCurrentName())) {
                ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.EntitySet) entitySet)
                        .setIncludeInServiceDocument(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("NavigationPropertyBinding".equals(jp.getCurrentName())) {
                jp.nextToken();//from  w ww  . j a v  a2  s  .  c  o  m
                ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.EntitySet) entitySet)
                        .getNavigationPropertyBindings()
                        .add(jp.getCodec().readValue(jp, NavigationPropertyBinding.class));
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.EntitySet) entitySet)
                        .setAnnotation(jp.getCodec().readValue(jp, Annotation.class));
            }
        }
    }

    return entitySet;
}

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

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

    final AbstractEnumType enumType = ODataVersion.V3 == client.getWorkingVersion()
            ? new com.msopentech.odatajclient.engine.data.metadata.edm.v3.EnumType()
            : new com.msopentech.odatajclient.engine.data.metadata.edm.v4.EnumType();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                enumType.setName(jp.nextTextValue());
            } else if ("UnderlyingType".equals(jp.getCurrentName())) {
                enumType.setUnderlyingType(jp.nextTextValue());
            } else if ("IsFlags".equals(jp.getCurrentName())) {
                enumType.setFlags(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("Member".equals(jp.getCurrentName())) {
                jp.nextToken();/*from w ww  .  j a va2  s. com*/
                if (enumType instanceof com.msopentech.odatajclient.engine.data.metadata.edm.v3.EnumType) {
                    ((com.msopentech.odatajclient.engine.data.metadata.edm.v3.EnumType) enumType).getMembers()
                            .add(jp.getCodec().readValue(jp,
                                    com.msopentech.odatajclient.engine.data.metadata.edm.v3.Member.class));
                } else {
                    ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.EnumType) enumType).getMembers()
                            .add(jp.getCodec().readValue(jp,
                                    com.msopentech.odatajclient.engine.data.metadata.edm.v4.Member.class));
                }
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.EnumType) enumType)
                        .setAnnotation(jp.getCodec().readValue(jp, Annotation.class));
            }
        }
    }

    return enumType;
}

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

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

    final AbstractComplexType complexType = ODataVersion.V3 == client.getWorkingVersion()
            ? new com.msopentech.odatajclient.engine.metadata.edm.v3.ComplexType()
            : new com.msopentech.odatajclient.engine.metadata.edm.v4.ComplexType();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                complexType.setName(jp.nextTextValue());
            } else if ("Abstract".equals(jp.getCurrentName())) {
                ((com.msopentech.odatajclient.engine.metadata.edm.v4.ComplexType) complexType)
                        .setAbstractEntityType(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("BaseType".equals(jp.getCurrentName())) {
                ((com.msopentech.odatajclient.engine.metadata.edm.v4.ComplexType) complexType)
                        .setBaseType(jp.nextTextValue());
            } else if ("OpenType".equals(jp.getCurrentName())) {
                ((com.msopentech.odatajclient.engine.metadata.edm.v4.ComplexType) complexType)
                        .setOpenType(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("Property".equals(jp.getCurrentName())) {
                jp.nextToken();//from  w  w w .j av  a 2 s  .  co m
                if (complexType instanceof com.msopentech.odatajclient.engine.metadata.edm.v3.ComplexType) {
                    ((com.msopentech.odatajclient.engine.metadata.edm.v3.ComplexType) complexType)
                            .getProperties().add(jp.getCodec().readValue(jp,
                                    com.msopentech.odatajclient.engine.metadata.edm.v3.Property.class));
                } else {
                    ((com.msopentech.odatajclient.engine.metadata.edm.v4.ComplexType) complexType)
                            .getProperties().add(jp.getCodec().readValue(jp,
                                    com.msopentech.odatajclient.engine.metadata.edm.v4.Property.class));
                }
            } else if ("NavigationProperty".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((com.msopentech.odatajclient.engine.metadata.edm.v4.ComplexType) complexType)
                        .getNavigationProperties().add(jp.getCodec().readValue(jp,
                                com.msopentech.odatajclient.engine.metadata.edm.v4.NavigationProperty.class));
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((com.msopentech.odatajclient.engine.metadata.edm.v4.ComplexType) complexType)
                        .setAnnotation(jp.getCodec().readValue(jp, Annotation.class));
            }
        }
    }

    return complexType;
}

From source file:com.reprezen.swagedit.model.NodeDeserializer.java

protected ObjectNode deserializeObjectNode(JsonParser p, DeserializationContext context,
        JsonLocation startLocation) throws IllegalArgumentException, IOException {

    final Model model = (Model) context.getAttribute(ATTRIBUTE_MODEL);
    final AbstractNode parent = (AbstractNode) context.getAttribute(ATTRIBUTE_PARENT);
    final JsonPointer ptr = (JsonPointer) context.getAttribute(ATTRIBUTE_POINTER);

    final ObjectNode node = model.objectNode(parent, ptr);
    node.setStartLocation(createLocation(startLocation));

    while (p.nextToken() != JsonToken.END_OBJECT) {
        String name = p.getCurrentName();

        JsonPointer pp = JsonPointer.compile(ptr.toString() + "/" + name.replaceAll("/", "~1"));
        context.setAttribute(ATTRIBUTE_PARENT, node);
        context.setAttribute(ATTRIBUTE_POINTER, pp);

        AbstractNode v = deserialize(p, context);
        v.setProperty(name);//w w w.  j ava2s . c o  m
        node.put(name, v);
    }

    node.setEndLocation(createLocation(p.getCurrentLocation()));
    return node;
}

From source file:org.emfjson.jackson.streaming.StreamReader.java

protected EObject parseObject(JsonParser parser, EReference containment, EObject owner, EClass currentClass)
        throws IOException {

    EObject current = null;/* w  w w.j a va 2 s .  c  o  m*/

    if (currentClass != null) {
        current = EcoreUtil.create(currentClass);
    }

    final TokenBuffer buffer = new TokenBuffer(parser);

    while (parser.nextToken() != JsonToken.END_OBJECT) {
        final String fieldName = parser.getCurrentName();

        switch (fieldName) {
        case EJS_TYPE_KEYWORD:
            current = create(parser.nextTextValue());
            break;
        case EJS_UUID_ANNOTATION:
            if (resource instanceof UuidResource) {
                if (current != null) {
                    ((UuidResource) resource).setID(current, parser.nextTextValue());
                }
            }
            break;
        default:
            if (current == null && containment != null) {
                final EClass defaultType = containment.getEReferenceType();

                if (!defaultType.isAbstract()) {
                    current = EcoreUtil.create(defaultType);
                }
            }

            if (current != null) {
                readFeature(parser, current, fieldName);
            } else {
                buffer.copyCurrentStructure(parser);
            }
            break;
        }
    }

    buffer.close();

    if (current != null) {
        final JsonParser bufferedParser = buffer.asParser();

        while (bufferedParser.nextToken() != null) {
            readFeature(bufferedParser, current, bufferedParser.getCurrentName());
        }

        bufferedParser.close();
    }

    if (current != null && containment != null && owner != null) {
        EObjects.setOrAdd(owner, containment, current);
    }

    return current;
}

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

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

    final AbstractComplexType complexType = ODataVersion.V3 == client.getWorkingVersion()
            ? new com.msopentech.odatajclient.engine.data.metadata.edm.v3.ComplexType()
            : new com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType();

    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        final JsonToken token = jp.getCurrentToken();
        if (token == JsonToken.FIELD_NAME) {
            if ("Name".equals(jp.getCurrentName())) {
                complexType.setName(jp.nextTextValue());
            } else if ("Abstract".equals(jp.getCurrentName())) {
                ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType) complexType)
                        .setAbstractEntityType(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("BaseType".equals(jp.getCurrentName())) {
                ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType) complexType)
                        .setBaseType(jp.nextTextValue());
            } else if ("OpenType".equals(jp.getCurrentName())) {
                ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType) complexType)
                        .setOpenType(BooleanUtils.toBoolean(jp.nextTextValue()));
            } else if ("Property".equals(jp.getCurrentName())) {
                jp.nextToken();/*from w w  w .  j  a  va  2  s .  c  o m*/
                if (complexType instanceof com.msopentech.odatajclient.engine.data.metadata.edm.v3.ComplexType) {
                    ((com.msopentech.odatajclient.engine.data.metadata.edm.v3.ComplexType) complexType)
                            .getProperties().add(jp.getCodec().readValue(jp,
                                    com.msopentech.odatajclient.engine.data.metadata.edm.v3.Property.class));
                } else {
                    ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType) complexType)
                            .getProperties().add(jp.getCodec().readValue(jp,
                                    com.msopentech.odatajclient.engine.data.metadata.edm.v4.Property.class));
                }
            } else if ("NavigationProperty".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType) complexType)
                        .getNavigationProperties().add(jp.getCodec().readValue(jp,
                                com.msopentech.odatajclient.engine.data.metadata.edm.v4.NavigationProperty.class));
            } else if ("Annotation".equals(jp.getCurrentName())) {
                jp.nextToken();
                ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType) complexType)
                        .setAnnotation(jp.getCodec().readValue(jp, Annotation.class));
            }
        }
    }

    return complexType;
}