Search in sources :

Example 36 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project atlasmap by atlasmap.

the class ActionsJsonDeserializer method processPrependJsonToken.

protected Prepend processPrependJsonToken(JsonParser jsonToken) throws IOException {
    Prepend action = new Prepend();
    if (JsonToken.END_ARRAY.equals(jsonToken.currentToken()) || JsonToken.END_OBJECT.equals(jsonToken.currentToken())) {
        return action;
    }
    JsonToken nextToken = null;
    do {
        if (JsonToken.START_OBJECT.equals(jsonToken.currentToken())) {
            jsonToken.nextToken();
        }
        switch(jsonToken.getCurrentName()) {
            case ActionsJsonSerializer.STRING:
                jsonToken.nextToken();
                action.setString(jsonToken.getValueAsString());
                break;
            default:
                break;
        }
        nextToken = jsonToken.nextToken();
    } while (!JsonToken.END_ARRAY.equals(nextToken) && !JsonToken.END_OBJECT.equals(nextToken));
    return action;
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 37 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project Payara by payara.

the class ProgressStatusDTOJsonProprietaryReader method readFrom.

@Override
public ProgressStatusDTO readFrom(final InputStream is, final String contentType) throws IOException {
    try (JsonParser jp = factory.createJsonParser(is)) {
        // sorounding object
        JsonToken token = jp.nextToken();
        // Name progress-status
        jp.nextToken();
        JsonToken token2 = jp.nextToken();
        if (token != JsonToken.START_OBJECT || token2 != JsonToken.START_OBJECT || !"progress-status".equals(jp.getCurrentName())) {
            throw new IOException("Not expected type (progress-status) but (" + jp.getCurrentName() + ")");
        }
        return readProgressStatus(jp);
    }
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 38 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project Payara by payara.

the class ProgressStatusEventJsonProprietaryReader method readFrom.

@Override
public ProgressStatusEvent readFrom(final InputStream is, final String contentType) throws IOException {
    try (JsonParser jp = factory.createJsonParser(is)) {
        // sorounding object
        JsonToken token = jp.nextToken();
        // Name progress-status-event
        jp.nextToken();
        JsonToken token2 = jp.nextToken();
        if (token != JsonToken.START_OBJECT || token2 != JsonToken.START_OBJECT || !"progress-status-event".equals(jp.getCurrentName())) {
            throw new IOException("Not expected type (progress-status-event) but (" + jp.getCurrentName() + ")");
        }
        return readProgressStatusEvent(jp);
    }
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 39 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project openhab1-addons by openhab.

the class JsonWeatherParser method handleToken.

/**
     * Iterates through the JSON structure and collects weather data.
     */
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 if (token != null) {
        try {
            setValue(weather, prop, jp.getValueAsString());
        } catch (Exception ex) {
            logger.error("Error setting property '{}' with value '{}' ({})", prop, jp.getValueAsString(), ex.getMessage());
        }
    }
}
Also used : Weather(org.openhab.binding.weather.internal.model.Weather) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 40 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project moco by dreamhead.

the class LatencyContainerDeserializer method deserialize.

@Override
public LatencyContainer deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
    JsonToken currentToken = jp.getCurrentToken();
    if (currentToken == JsonToken.VALUE_NUMBER_INT) {
        return LatencyContainer.latency(jp.getLongValue());
    }
    if (currentToken == JsonToken.START_OBJECT) {
        jp.nextToken();
        InternalLatencyContainer container = get(jp.readValuesAs(InternalLatencyContainer.class), 0);
        return LatencyContainer.latencyWithUnit(container.duration, TimeUnit.valueOf(container.unit.toUpperCase() + 'S'));
    }
    return (LatencyContainer) ctxt.handleUnexpectedToken(LatencyContainer.class, jp);
}
Also used : LatencyContainer(com.github.dreamhead.moco.parser.model.LatencyContainer) JsonToken(com.fasterxml.jackson.core.JsonToken)

Aggregations

JsonToken (com.fasterxml.jackson.core.JsonToken)72 JsonParser (com.fasterxml.jackson.core.JsonParser)14 IOException (java.io.IOException)14 ArrayList (java.util.ArrayList)8 SqlNullable (com.facebook.presto.spi.function.SqlNullable)7 SqlType (com.facebook.presto.spi.function.SqlType)7 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)7 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)6 JsonParserHelper.assertExpectedJsonToken (com.alibaba.json.test.performance.JacksonPageModelParser.JsonParserHelper.assertExpectedJsonToken)5 JsonParseException (com.fasterxml.jackson.core.JsonParseException)3 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)2 RpcHint (com.navercorp.pinpoint.web.filter.RpcHint)2 InputStream (java.io.InputStream)2 ValueSerializationException (org.qi4j.api.value.ValueSerializationException)2 Company (com.alibaba.json.test.entity.Company)1 Department (com.alibaba.json.test.entity.Department)1 Employee (com.alibaba.json.test.entity.Employee)1 Group (com.alibaba.json.test.entity.Group)1 LayoutInstance (com.alibaba.json.test.entity.pagemodel.LayoutInstance)1 PageInstance (com.alibaba.json.test.entity.pagemodel.PageInstance)1