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

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

Introduction

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

Prototype

public abstract JsonToken nextValue() throws IOException, JsonParseException;

Source Link

Document

Iteration method that will advance stream enough to determine type of the next token that is a value type (including JSON Array and Object start/end markers).

Usage

From source file:org.openhab.binding.weather.internal.parser.JsonWeatherParser.java

@Override
public void parseInto(String r, Weather weather) throws Exception {
    JsonFactory jsonFactory = new JsonFactory();
    JsonParser jp = jsonFactory.createParser(r);

    jp.nextValue();
    handleToken(jp, null, weather);//from ww w .j a v  a2 s .  com
    jp.close();

    super.parseInto(r, weather);
}

From source file:org.openhab.binding.weather.internal.parser.JsonWeatherParser.java

/**
 * Iterates through the JSON structure and collects weather data.
 *//*  w ww  .jav a 2 s . c  o m*/
private void handleToken(JsonParser jp, String property, Weather weather) throws Exception {
    JsonToken token = jp.getCurrentToken();
    String prop = PropertyResolver.add(property, jp.getCurrentName());

    if (token.isStructStart()) {
        boolean isObject = token == JsonToken.START_OBJECT || token == JsonToken.END_OBJECT;

        Weather forecast = !isObject ? weather : startIfForecast(weather, prop);
        while (!jp.nextValue().isStructEnd()) {
            handleToken(jp, prop, forecast);
        }
        if (isObject) {
            endIfForecast(weather, forecast, prop);
        }
    } else {
        try {
            setValue(weather, prop, jp.getValueAsString());
        } catch (Exception ex) {
            logger.error("Error setting property '{}' with value '{}' ({})", prop, jp.getValueAsString(),
                    ex.getMessage());
        }
    }
}