Example usage for com.fasterxml.jackson.core JsonToken END_OBJECT

List of usage examples for com.fasterxml.jackson.core JsonToken END_OBJECT

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonToken END_OBJECT.

Prototype

JsonToken END_OBJECT

To view the source code for com.fasterxml.jackson.core JsonToken END_OBJECT.

Click Source Link

Document

END_OBJECT is returned when encountering '}' which signals ending of an Object value

Usage

From source file:com.amazonaws.services.cloudtrail.processinglibrary.serializer.AbstractEventSerializer.java

/**
 * Parse a single Resource/*from www.j  ava  2s.c  o m*/
 *
 * @return a single resource
 * @throws IOException
 */
private Resource parseResource() throws IOException {
    //current token is ready consumed by parseResources
    if (this.jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
        throw new JsonParseException("Not a Resource object", this.jsonParser.getCurrentLocation());
    }

    Resource resource = new Resource();

    while (this.jsonParser.nextToken() != JsonToken.END_OBJECT) {
        String key = this.jsonParser.getCurrentName();

        switch (key) {
        default:
            resource.add(key, this.parseDefaultValue(key));
            break;
        }
    }

    return resource;
}

From source file:com.github.heuermh.personalgenome.client.converter.JacksonPersonalGenomeConverter.java

@Override
public Ancestry parseAncestry(final InputStream inputStream) {
    checkNotNull(inputStream);//from w w w  .j a v a  2 s  .  c  o m
    JsonParser parser = null;
    try {
        parser = jsonFactory.createParser(inputStream);
        parser.nextToken();

        String id = null;
        String label = null;
        double proportion = 0.0d;
        double unassigned = 0.0d;
        List<Ancestry> subPopulations = new ArrayList<Ancestry>();
        while (parser.nextToken() != JsonToken.END_OBJECT) {
            String field = parser.getCurrentName();
            parser.nextToken();

            if ("id".equals(field)) {
                id = parser.getText();
            } else if ("ancestry".equals(field)) {
                while (parser.nextToken() != JsonToken.END_OBJECT) {
                    String ancestryField = parser.getCurrentName();
                    parser.nextToken();

                    if ("label".equals(ancestryField)) {
                        label = parser.getText();
                    } else if ("proportion".equals(ancestryField)) {
                        proportion = Double.parseDouble(parser.getText());
                    } else if ("unassigned".equals(ancestryField)) {
                        unassigned = Double.parseDouble(parser.getText());
                    } else if ("sub_populations".equals(ancestryField)) {
                        subPopulations = parseSubPopulation(id, subPopulations, parser);
                    }
                }
            }
        }
        return new Ancestry(id, label, proportion, unassigned, subPopulations);
    } catch (IOException e) {
        logger.warn("could not parse ancestry", e);
    } finally {
        try {
            inputStream.close();
        } catch (Exception e) {
            // ignored
        }
        try {
            parser.close();
        } catch (Exception e) {
            // ignored
        }
    }
    return null;
}

From source file:com.netflix.hollow.jsonadapter.HollowJsonAdapter.java

private int addUnstructuredMap(JsonParser parser, String mapTypeName, HollowMapWriteRecord mapRec)
        throws IOException {
    mapRec.reset();/*  www. j a  v a  2s .  co m*/

    HollowMapSchema schema = (HollowMapSchema) hollowSchemas.get(mapTypeName);
    ObjectFieldMapping valueRec = null;
    ObjectMappedFieldPath fieldMapping = null;

    JsonToken token = parser.nextToken();

    while (token != JsonToken.END_OBJECT) {
        if (token != JsonToken.FIELD_NAME) {
            HollowObjectWriteRecord mapKeyWriteRecord = (HollowObjectWriteRecord) getWriteRecord(
                    schema.getKeyType());
            String fieldName = mapKeyWriteRecord.getSchema().getFieldName(0);
            mapKeyWriteRecord.reset();

            switch (mapKeyWriteRecord.getSchema().getFieldType(0)) {
            case STRING:
                mapKeyWriteRecord.setString(fieldName, parser.getCurrentName());
                break;
            case BOOLEAN:
                mapKeyWriteRecord.setBoolean(fieldName, Boolean.valueOf(parser.getCurrentName()));
                break;
            case INT:
                mapKeyWriteRecord.setInt(fieldName, Integer.parseInt(parser.getCurrentName()));
                break;
            case LONG:
                mapKeyWriteRecord.setLong(fieldName, Long.parseLong(parser.getCurrentName()));
                break;
            case DOUBLE:
                mapKeyWriteRecord.setDouble(fieldName, Double.parseDouble(parser.getCurrentName()));
                break;
            case FLOAT:
                mapKeyWriteRecord.setFloat(fieldName, Float.parseFloat(parser.getCurrentName()));
                break;
            default:
                throw new IOException("Cannot parse type " + mapKeyWriteRecord.getSchema().getFieldType(0)
                        + " as key in map (" + mapKeyWriteRecord.getSchema().getName() + ")");
            }

            int keyOrdinal = stateEngine.add(schema.getKeyType(), mapKeyWriteRecord);

            int valueOrdinal;

            if (token == JsonToken.START_OBJECT || token == JsonToken.START_ARRAY) {
                valueOrdinal = parseSubType(parser, token, schema.getValueType());
            } else {
                if (valueRec == null) {
                    valueRec = getObjectFieldMapping(schema.getValueType());
                    fieldMapping = valueRec.getSingleFieldMapping();
                }
                addObjectField(parser, token, fieldMapping);
                valueOrdinal = valueRec.build(-1);
            }

            mapRec.addEntry(keyOrdinal, valueOrdinal);
        }
        token = parser.nextToken();
    }

    return stateEngine.add(schema.getName(), mapRec);
}

From source file:org.h2gis.drivers.geojson.GeoJsonReaderDriver.java

/**
 * Features in GeoJSON contain a geometry object and additional properties
 *
 * Syntax://w w  w. j  a  va2  s.c  om
 *
 * { "type": "Feature", "geometry":{"type": "Point", "coordinates": [102.0,
 * 0.5]}, "properties": {"prop0": "value0"} }
 *
 * @param jsParser
 */
private void parseFeature(JsonParser jp) throws IOException, SQLException {
    jp.nextToken(); // FIELD_NAME geometry
    String firstField = jp.getText();
    fieldIndex = 1;
    if (firstField.equalsIgnoreCase(GeoJsonField.GEOMETRY)) {
        jp.nextToken(); //START_OBJECT {
        getPreparedStatement().setObject(fieldIndex, parseGeometry(jp));
        fieldIndex++;
    } else if (firstField.equalsIgnoreCase(GeoJsonField.PROPERTIES)) {
        parseProperties(jp, fieldIndex);
    }
    //If there is only one geometry field in the feature them the next
    //token corresponds to the end object of the feature
    jp.nextToken();
    if (jp.getCurrentToken() != JsonToken.END_OBJECT) {
        String secondParam = jp.getText();// field name
        if (secondParam.equalsIgnoreCase(GeoJsonField.GEOMETRY)) {
            jp.nextToken(); //START_OBJECT {
            getPreparedStatement().setObject(fieldIndex, parseGeometry(jp));
            fieldIndex++;
        } else if (secondParam.equalsIgnoreCase(GeoJsonField.PROPERTIES)) {
            parseProperties(jp, fieldIndex);
        }
        jp.nextToken(); //END_OBJECT } feature
    }
    if (!hasProperties) {
        getPreparedStatement().setObject(fieldIndex, featureCounter);
    }
    getPreparedStatement().execute();
}

From source file:com.github.shyiko.jackson.module.advice.AdvisedBeanDeserializer.java

/**
 * Method called when there are declared "unwrapped" properties
 * which need special handling/*from w  w w. j  a v  a 2  s. c  om*/
 */
@SuppressWarnings("resource")
protected Object deserializeWithUnwrapped(JsonParser jp, DeserializationContext ctxt) throws IOException {
    if (_delegateDeserializer != null) {
        return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.deserialize(jp, ctxt));
    }
    if (_propertyBasedCreator != null) {
        return deserializeUsingPropertyBasedWithUnwrapped(jp, ctxt);
    }
    TokenBuffer tokens = new TokenBuffer(jp);
    tokens.writeStartObject();
    final Object bean = _valueInstantiator.createUsingDefault(ctxt);

    if (_injectables != null) {
        injectValues(ctxt, bean);
    }
    final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
    beanDeserializerAdvice.before(bean, jp, ctxt);
    for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
        String propName = jp.getCurrentName();
        jp.nextToken();

        if (beanDeserializerAdvice.intercept(bean, propName, jp, ctxt)) {
            continue;
        }

        SettableBeanProperty prop = _beanProperties.find(propName);
        if (prop != null) { // normal case
            if (activeView != null && !prop.visibleInView(activeView)) {
                jp.skipChildren();
                continue;
            }
            try {
                prop.deserializeAndSet(jp, ctxt, bean);
            } catch (Exception e) {
                wrapAndThrow(e, bean, propName, ctxt);
            }
            continue;
        }
        // ignorable things should be ignored
        if (_ignorableProps != null && _ignorableProps.contains(propName)) {
            handleIgnoredProperty(jp, ctxt, bean, propName);
            continue;
        }
        // but... others should be passed to unwrapped property deserializers
        tokens.writeFieldName(propName);
        tokens.copyCurrentStructure(jp);
        // how about any setter? We'll get copies but...
        if (_anySetter != null) {
            try {
                _anySetter.deserializeAndSet(jp, ctxt, bean, propName);
            } catch (Exception e) {
                wrapAndThrow(e, bean, propName, ctxt);
            }
            continue;
        }
    }
    tokens.writeEndObject();
    _unwrappedPropertyHandler.processUnwrapped(jp, ctxt, bean, tokens);
    beanDeserializerAdvice.after(bean, jp, ctxt);
    return bean;
}

From source file:io.protostuff.JsonIOUtil.java

/**
 * Parses the {@code messages} from the parser using the given {@code schema}.
 *//*  ww  w . j ava 2 s. co m*/
public static <T> List<T> parseListFrom(JsonParser parser, Schema<T> schema, boolean numeric)
        throws IOException {
    if (parser.nextToken() != JsonToken.START_ARRAY) {
        throw new JsonInputException("Expected token: [ but was " + parser.getCurrentToken() + " on message: "
                + schema.messageFullName());
    }

    final JsonInput input = new JsonInput(parser, numeric);
    final List<T> list = new ArrayList<>();
    for (JsonToken t = parser.nextToken(); t != JsonToken.END_ARRAY; t = parser.nextToken()) {
        if (t != JsonToken.START_OBJECT) {
            throw new JsonInputException("Expected token: { but was " + parser.getCurrentToken()
                    + " on message " + schema.messageFullName());
        }

        final T message = schema.newMessage();
        schema.mergeFrom(input, message);

        if (parser.getCurrentToken() != JsonToken.END_OBJECT) {
            throw new JsonInputException("Expected token: } but was " + parser.getCurrentToken()
                    + " on message " + schema.messageFullName());
        }

        list.add(message);
        input.reset();
    }
    return list;
}

From source file:com.amazonaws.services.cloudtrail.processinglibrary.serializer.AbstractEventSerializer.java

/**
 * Parse attributes as a Map, used in both parseWebIdentitySessionContext and parseSessionContext
 *
 * @return attributes for either session context or web identity session context
 * @throws IOException/*www .  j ava2  s . c  o  m*/
 */
private Map<String, String> parseAttributes() throws IOException {
    if (this.jsonParser.nextToken() != JsonToken.START_OBJECT) {
        throw new JsonParseException("Not a Attributes object", this.jsonParser.getCurrentLocation());
    }

    Map<String, String> attributes = new HashMap<>();

    while (this.jsonParser.nextToken() != JsonToken.END_OBJECT) {
        String key = this.jsonParser.getCurrentName();
        String value = this.jsonParser.nextTextValue();
        attributes.put(key, value);
    }

    return attributes;
}

From source file:com.github.heuermh.personalgenome.client.converter.JacksonPersonalGenomeConverter.java

@Override
public double parseNeanderthalProportion(final InputStream inputStream) {
    checkNotNull(inputStream);//from  w  w  w .  j  a va 2  s .c  o m
    JsonParser parser = null;
    try {
        parser = jsonFactory.createParser(inputStream);
        parser.nextToken();

        double proportion = -1d;
        while (parser.nextToken() != JsonToken.END_OBJECT) {
            String field = parser.getCurrentName();
            parser.nextToken();

            if ("neanderthal".equals(field)) {
                while (parser.nextToken() != JsonToken.END_OBJECT) {
                    String neanderthalField = parser.getCurrentName();
                    parser.nextToken();

                    if ("proportion".equals(neanderthalField)) {
                        proportion = Double.parseDouble(parser.getText());
                    }
                }
            }
        }
        return proportion;
    } catch (IOException e) {
        logger.warn("could not parse neanderthal proportion", e);
    } finally {
        try {
            inputStream.close();
        } catch (Exception e) {
            // ignored
        }
        try {
            parser.close();
        } catch (Exception e) {
            // ignored
        }
    }
    return -1d;
}

From source file:com.quinsoft.zeidon.standardoe.ActivateOisFromJsonStream.java

private AttributeMeta readAttributeMeta(EntityInstanceImpl ei, String fieldName)
        throws JsonParseException, IOException {
    String attribName = fieldName.substring(1); // Remove the ".".
    AttributeMeta meta = new AttributeMeta();
    meta.attributeDef = ei.getEntityDef().getAttribute(attribName, true, true);

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

        if (fieldName.equals("updated"))
            meta.updated = true;//from ww  w .  j  a  v  a 2  s  .  com
        else
            task.log().warn("Unknown entity meta value %s", fieldName);
    }

    return meta;
}

From source file:com.netflix.hollow.jsonadapter.HollowJsonAdapter.java

private void skipObject(JsonParser parser) throws IOException {
    JsonToken token = parser.nextToken();

    try {//w w  w.j  a v a 2 s . c o  m
        while (token != JsonToken.END_OBJECT) {
            skipObjectField(parser, token);
            token = parser.nextToken();
        }
    } catch (Exception ex) {
        throw new IOException(ex);
    }
}