Search in sources :

Example 11 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project fastjson by alibaba.

the class JacksonPageModelParser method parseSegments.

/**
     * @param parser
     * @throws JsonParseException
     * @throws IOException
     */
private List<SegmentInstance> parseSegments(JsonParser parser) throws JsonParseException, IOException {
    JsonToken current = parser.nextToken();
    assertExpectedJsonToken(current, JsonToken.START_ARRAY, parser.getCurrentLocation());
    List<SegmentInstance> instances = new ArrayList<SegmentInstance>();
    while ((current = parser.nextToken()) != JsonToken.END_ARRAY) {
        assertExpectedJsonToken(current, JsonToken.START_OBJECT, parser.getCurrentLocation());
        // get pageId
        String segmentId = getNextTextValue("cid", parser);
        // move to field: layouts
        current = parser.nextToken();
        assertExpectedFiled(parser.getCurrentName(), "layouts", parser.getCurrentLocation());
        SegmentInstance instance = new SegmentInstance();
        instance.setLayouts(parseLayouts(parser, segmentId));
        instances.add(instance);
        assertExpectedJsonToken((current = parser.nextToken()), JsonToken.END_OBJECT, parser.getCurrentLocation());
    }
    return instances;
}
Also used : SegmentInstance(com.alibaba.json.test.entity.pagemodel.SegmentInstance) ArrayList(java.util.ArrayList) JsonToken(com.fasterxml.jackson.core.JsonToken) JsonParserHelper.assertExpectedJsonToken(com.alibaba.json.test.performance.JacksonPageModelParser.JsonParserHelper.assertExpectedJsonToken)

Example 12 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project pinpoint by naver.

the class FilterHintListJsonDeserializer method deserialize.

@Override
public FilterHint deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    if (!jp.getCurrentToken().isStructStart()) {
        throw ctxt.mappingException(RpcHint.class, jp.getCurrentToken());
    }
    // skip json start
    final JsonToken jsonToken = jp.nextToken();
    if (jsonToken == JsonToken.END_OBJECT) {
        return new FilterHint(Collections.<RpcHint>emptyList());
    }
    List<RpcHint> rpcHintList = new ArrayList<>();
    while (true) {
        final RpcHint rpcHint = jp.readValueAs(RpcHint.class);
        rpcHintList.add(rpcHint);
        if (jp.nextToken() == JsonToken.END_OBJECT) {
            break;
        }
    }
    return new FilterHint(rpcHintList);
}
Also used : FilterHint(com.navercorp.pinpoint.web.filter.FilterHint) ArrayList(java.util.ArrayList) JsonToken(com.fasterxml.jackson.core.JsonToken) RpcHint(com.navercorp.pinpoint.web.filter.RpcHint)

Example 13 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project pinpoint by naver.

the class RpcHintJsonDeserializer method deserialize.

@Override
public RpcHint deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    final String applicationName = jp.getText();
    if (jp.nextToken() != JsonToken.START_ARRAY) {
        throw ctxt.mappingException(RpcHint.class, jp.getCurrentToken());
    }
    // skip start array
    final JsonToken token = jp.nextToken();
    // [] empty array
    if (token == JsonToken.END_ARRAY) {
        return new RpcHint(applicationName, Collections.<RpcType>emptyList());
    }
    final List<RpcType> rpcHintList = new ArrayList<>();
    while (true) {
        RpcType rpcType = jp.readValueAs(RpcType.class);
        rpcHintList.add(rpcType);
        if (jp.nextToken() == JsonToken.END_ARRAY) {
            break;
        }
    }
    return new RpcHint(applicationName, rpcHintList);
}
Also used : RpcType(com.navercorp.pinpoint.web.filter.RpcType) ArrayList(java.util.ArrayList) JsonToken(com.fasterxml.jackson.core.JsonToken) RpcHint(com.navercorp.pinpoint.web.filter.RpcHint)

Example 14 with JsonToken

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

the class JsonMetricDataStream method accept.

@Override
public void accept(MetricDataVisitor visitor) throws IOException {
    while (true) {
        JsonToken token = jsonParser.nextToken();
        if (token == null) {
            break;
        }
        switch(token) {
            case START_OBJECT:
                visitor.startObject();
                break;
            case END_OBJECT:
                visitor.endObject();
                break;
            case VALUE_STRING:
                {
                    String s = jsonParser.getText();
                    visitor.gotValueString(s);
                    break;
                }
            case FIELD_NAME:
                {
                    String key = jsonParser.getText();
                    visitor.gotKey(key);
                    break;
                }
            case START_ARRAY:
                visitor.startArray();
                break;
            case END_ARRAY:
                visitor.endArray();
                break;
            case VALUE_FALSE:
                visitor.gotValueBoolean(false);
                break;
            case VALUE_TRUE:
                visitor.gotValueBoolean(false);
                break;
            case VALUE_NULL:
                visitor.gotValueNull();
                break;
            case VALUE_NUMBER_FLOAT:
            case VALUE_NUMBER_INT:
                {
                    NumberType numberType = jsonParser.getNumberType();
                    switch(numberType) {
                        case BIG_INTEGER:
                        case BIG_DECIMAL:
                            {
                                throw new UnsupportedOperationException("Value too large: " + jsonParser.getBigIntegerValue());
                            }
                        case INT:
                            {
                                int v = jsonParser.getIntValue();
                                visitor.gotValueInt(v);
                                break;
                            }
                        case FLOAT:
                            {
                                float v = jsonParser.getFloatValue();
                                visitor.gotValueFloat(v);
                                break;
                            }
                        case DOUBLE:
                            {
                                double v = jsonParser.getDoubleValue();
                                visitor.gotValueDouble(v);
                                break;
                            }
                        case LONG:
                            {
                                long v = jsonParser.getLongValue();
                                visitor.gotValueLong(v);
                                break;
                            }
                        default:
                            throw new IllegalStateException("Unexpected number type: " + numberType);
                    }
                    break;
                }
            case NOT_AVAILABLE:
            case VALUE_EMBEDDED_OBJECT:
            default:
                throw new IllegalStateException("Unexpected token: " + token);
        }
    }
}
Also used : NumberType(com.fasterxml.jackson.core.JsonParser.NumberType) JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 15 with JsonToken

use of com.fasterxml.jackson.core.JsonToken in project presto by prestodb.

the class JsonFunctions method jsonArrayContains.

@SqlNullable
@ScalarFunction
@SqlType(StandardTypes.BOOLEAN)
public static Boolean jsonArrayContains(@SqlType(StandardTypes.JSON) Slice json, @SqlType(StandardTypes.BOOLEAN) boolean value) {
    try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) {
        if (parser.nextToken() != START_ARRAY) {
            return null;
        }
        while (true) {
            JsonToken token = parser.nextToken();
            if (token == null) {
                return null;
            }
            if (token == END_ARRAY) {
                return false;
            }
            parser.skipChildren();
            if (((token == VALUE_TRUE) && value) || ((token == VALUE_FALSE) && (!value))) {
                return true;
            }
        }
    } catch (IOException e) {
        return null;
    }
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) JsonUtil.createJsonParser(com.facebook.presto.util.JsonUtil.createJsonParser) JsonParser(com.fasterxml.jackson.core.JsonParser) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) SqlType(com.facebook.presto.spi.function.SqlType)

Aggregations

JsonToken (com.fasterxml.jackson.core.JsonToken)46 JsonParser (com.fasterxml.jackson.core.JsonParser)11 IOException (java.io.IOException)10 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 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)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