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:name.gumartinm.weather.information.parser.JPOSForecastParser.java

private void getForecastWeatherData(final Forecast forecastWeatherData, final JsonParser jParser)
        throws JsonParseException, IOException {
    if (jParser.nextToken() == JsonToken.START_OBJECT) {

        while (jParser.nextToken() != JsonToken.END_OBJECT) {
            final String fieldname = jParser.getCurrentName();
            final JsonToken nextToken = jParser.nextToken();
            if (nextToken == JsonToken.START_OBJECT) {
                this.getForecastWeatherDataObjects(forecastWeatherData, jParser, fieldname);
            }//from w w w . j  a  va  2 s. c  om
            if (nextToken == JsonToken.START_ARRAY) {
                JsonToken tokenNext = jParser.nextToken();
                while (tokenNext != JsonToken.END_ARRAY) {
                    if (tokenNext == JsonToken.START_OBJECT) {
                        this.getForecastWeatherDataObjects(forecastWeatherData, jParser, fieldname);
                    }
                    tokenNext = jParser.nextToken();
                }
            }
            if ((nextToken == JsonToken.VALUE_NUMBER_INT) || (nextToken == JsonToken.VALUE_STRING)) {
                this.getForecastWeatherDataObjects(forecastWeatherData, jParser, fieldname);
            }
        }
    }
}

From source file:KV78Tester.java

public void checkLines(BufferedReader in) throws JsonParseException, IOException {
    JsonFactory f = new JsonFactory();
    JsonParser jp = f.createJsonParser(in);
    String line = "";
    jp.nextToken();/*from   w  ww .ja v  a2 s  .co m*/
    while (jp.nextToken() != JsonToken.END_OBJECT) {
        String namefield = jp.getCurrentName();
        if (namefield != null && namefield.contains("_")) {
            line = namefield;
        }
        jp.nextToken();
        if ("Actuals".equals(namefield)) {
            while (jp.nextToken() != JsonToken.END_OBJECT) {
                jp.getCurrentName();
                jp.nextToken();
                while (jp.nextToken() != JsonToken.END_OBJECT) {
                    jp.nextToken();
                }
            }
        } else if ("Network".equals(namefield)) {
            while (jp.nextToken() != JsonToken.END_OBJECT) {
                int userstop = Integer.parseInt(jp.getCurrentName());
                jp.nextToken();
                checkStop(jp, line, userstop);
            }
        }
    }
}

From source file:com.microsoft.azure.storage.core.JsonUtilities.java

/***
 * Reserved for internal use. Asserts that the current token of the parser is the end of an object.
 * // w  w  w  .j  a  va2s.c o  m
 * @param parser
 *            The {@link JsonParser} whose current token to check.
 */
public static void assertIsEndObjectJsonToken(final JsonParser parser) throws JsonParseException {
    if (!(parser.getCurrentToken() == JsonToken.END_OBJECT)) {
        throw new JsonParseException(SR.EXPECTED_END_OBJECT, parser.getCurrentLocation());
    }
}

From source file:com.microsoft.azure.storage.table.ODataUtilities.java

/***
 * Reserved for internal use. Asserts that the current token of the parser is the end of an object.
 * //from   w w w.  ja v  a  2  s . c  om
 * @param parser
 *            The {@link JsonParser} whose current token to check.
 */
protected static void assertIsEndObjectJsonToken(final JsonParser parser) throws JsonParseException {
    if (!(parser.getCurrentToken() == JsonToken.END_OBJECT)) {
        throw new JsonParseException(SR.EXPECTED_END_OBJECT, parser.getCurrentLocation());
    }
}

From source file:com.github.heuermh.ensemblrestclient.JacksonVariationConverter.java

static Variation parseVariation(final JsonFactory jsonFactory, final InputStream inputStream)
        throws IOException {
    JsonParser parser = null;//from   w ww. j  av a 2s . co m
    try {
        parser = jsonFactory.createParser(inputStream);
        parser.nextToken();

        String identifier = null;
        String referenceAllele = null;
        List<String> alternateAlleles = new ArrayList<String>();

        String locationName = null;
        String coordinateSystem = "chromosome";
        int start = -1;
        int end = -1;
        int strand = -1;

        while (parser.nextToken() != JsonToken.END_OBJECT) {
            String field = parser.getCurrentName();
            parser.nextToken();
            if ("name".equals(field)) {
                identifier = parser.getText();
            } else if ("mappings".equals(field)) {
                // todo:  will only catch last mapping
                while (parser.nextToken() != JsonToken.END_ARRAY) {
                    while (parser.nextToken() != JsonToken.END_OBJECT) {
                        String mappingsField = parser.getCurrentName();
                        parser.nextToken();

                        if ("seq_region_name".equals(mappingsField)) {
                            locationName = parser.getText();
                        } else if ("start".equals(mappingsField)) {
                            start = Integer.parseInt(parser.getText());
                        } else if ("end".equals(mappingsField)) {
                            end = Integer.parseInt(parser.getText());
                        } else if ("strand".equals(mappingsField)) {
                            strand = Integer.parseInt(parser.getText());
                        } else if ("allele_string".equals(mappingsField)) {
                            String[] tokens = parser.getText().split("/");
                            // todo:  check ref here against ancestral_allele
                            referenceAllele = tokens[0];
                            for (int i = 1; i < tokens.length; i++) {
                                alternateAlleles.add(tokens[i]);
                            }
                        }
                    }
                }
            } else if ("synonyms".equals(field)) {
                while (parser.nextToken() != JsonToken.END_ARRAY) {
                    // ignore
                }
            } else if ("evidence".equals(field)) {
                while (parser.nextToken() != JsonToken.END_ARRAY) {
                    // ignore
                }
            }
        }
        return new Variation(identifier, referenceAllele, alternateAlleles,
                new Location(locationName, coordinateSystem, start, end, strand));
    } finally {
        try {
            inputStream.close();
        } catch (Exception e) {
            // ignored
        }
        try {
            parser.close();
        } catch (Exception e) {
            // ignored
        }
    }
}

From source file:com.microsoft.azure.storage.core.EncryptionAgent.java

public static EncryptionAgent deserialize(JsonParser parser) throws JsonParseException, IOException {
    JsonUtilities.assertIsStartObjectJsonToken(parser);

    parser.nextToken();/*  ww w  . j a  va  2 s.  c o m*/

    EncryptionAgent agent = new EncryptionAgent();
    while (parser.getCurrentToken() != JsonToken.END_OBJECT) {
        String name = parser.getCurrentName();
        parser.nextToken();

        if (name.equals("Protocol")) {
            agent.setProtocol(parser.getValueAsString());
        } else if (name.equals("EncryptionAlgorithm")) {
            agent.setEncryptionAlgorithm(EncryptionAlgorithm.valueOf(parser.getValueAsString()));
        }
        parser.nextToken();
    }

    JsonUtilities.assertIsEndObjectJsonToken(parser);

    return agent;
}

From source file:io.apiman.manager.api.migrator.JsonDataMigratorReader.java

/**
 * @see io.apiman.manager.api.migrator.IDataMigratorReader#read(io.apiman.manager.api.migrator.IReaderHandler)
 *///from   w ww  . j ava2  s. c  o  m
@Override
public void read(IReaderHandler readerHandler) throws IOException {
    try {
        JsonToken current = jp.nextToken();

        if (current != JsonToken.START_OBJECT) {
            throw new IOException("Expected start object at root."); //$NON-NLS-1$
        }

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

            if (name.equals("Metadata")) { //$NON-NLS-1$
                ObjectNode obj = readObjectNode();
                readerHandler.onMetaData(obj);
            } else if (name.equals("Gateways")) { //$NON-NLS-1$
                readArrayStart();
                while (jp.getCurrentToken() == JsonToken.START_OBJECT) {
                    ObjectNode obj = readObjectNode();
                    readerHandler.onGateway(obj);
                    jp.nextToken();
                }
            } else if (name.equals("Plugins")) { //$NON-NLS-1$
                readArrayStart();
                while (jp.getCurrentToken() == JsonToken.START_OBJECT) {
                    ObjectNode obj = readObjectNode();
                    readerHandler.onPlugin(obj);
                    jp.nextToken();
                }
            } else if (name.equals("Roles")) { //$NON-NLS-1$
                readArrayStart();
                while (jp.getCurrentToken() == JsonToken.START_OBJECT) {
                    ObjectNode obj = readObjectNode();
                    readerHandler.onRole(obj);
                    jp.nextToken();
                }
            } else if (name.equals("PolicyDefinitions")) { //$NON-NLS-1$
                readArrayStart();
                while (jp.getCurrentToken() == JsonToken.START_OBJECT) {
                    ObjectNode obj = readObjectNode();
                    readerHandler.onPolicyDefinition(obj);
                    jp.nextToken();
                }
            } else if (name.equals("Users")) { //$NON-NLS-1$
                readArrayStart();
                while (jp.getCurrentToken() == JsonToken.START_OBJECT) {
                    ObjectNode obj = readObjectNode();
                    readerHandler.onUser(obj);
                    jp.nextToken();
                }
            } else if (name.equals("Orgs")) { //$NON-NLS-1$
                readArrayStart();
                while (jp.getCurrentToken() == JsonToken.START_OBJECT) {
                    ObjectNode obj = readObjectNode();
                    readerHandler.onOrg(obj);
                    jp.nextToken();
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(in);
    }
}

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);//from w  ww .  ja  v  a2s . c  o m
        node.put(name, v);
    }

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

From source file:org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Deserializer.java

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

    String tokenValue = null;/*  w w w.  j a v  a 2s  .  c o m*/
    String tokenType = null;
    String refreshToken = null;
    Long expiresIn = null;
    Set<String> scope = null;
    Map<String, Object> additionalInformation = new LinkedHashMap<String, Object>();

    // TODO What should occur if a parameter exists twice
    while (jp.nextToken() != JsonToken.END_OBJECT) {
        String name = jp.getCurrentName();
        jp.nextToken();
        if (OAuth2AccessToken.ACCESS_TOKEN.equals(name)) {
            tokenValue = jp.getText();
        } else if (OAuth2AccessToken.TOKEN_TYPE.equals(name)) {
            tokenType = jp.getText();
        } else if (OAuth2AccessToken.REFRESH_TOKEN.equals(name)) {
            refreshToken = jp.getText();
        } else if (OAuth2AccessToken.EXPIRES_IN.equals(name)) {
            try {
                expiresIn = jp.getLongValue();
            } catch (JsonParseException e) {
                expiresIn = Long.valueOf(jp.getText());
            }
        } else if (OAuth2AccessToken.SCOPE.equals(name)) {
            String text = jp.getText();
            scope = OAuth2Utils.parseParameterList(text);
        } else {
            additionalInformation.put(name, jp.readValueAs(Object.class));
        }
    }

    // TODO What should occur if a required parameter (tokenValue or tokenType) is missing?

    DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(tokenValue);
    accessToken.setTokenType(tokenType);
    if (expiresIn != null) {
        accessToken.setExpiration(new Date(System.currentTimeMillis() + (expiresIn * 1000)));
    }
    if (refreshToken != null) {
        accessToken.setRefreshToken(new DefaultOAuth2RefreshToken(refreshToken));
    }
    accessToken.setScope(scope);
    accessToken.setAdditionalInformation(additionalInformation);

    return accessToken;
}

From source file:org.apache.nifi.minifi.c2.provider.nifi.rest.TemplatesIterator.java

private Pair<String, String> getNext() throws IOException {
    while (parser.nextToken() != JsonToken.END_ARRAY) {
        if ("template".equals(parser.getCurrentName())) {
            String id = null;//from  w  ww.  ja v a2s  .c o  m
            String name = null;
            while (parser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = parser.getCurrentName();
                if ("id".equals(currentName)) {
                    parser.nextToken();
                    id = parser.getText();
                } else if ("name".equals(currentName)) {
                    parser.nextToken();
                    name = parser.getText();
                }
            }
            return new Pair<>(id, name);
        }
    }
    return null;
}