Search in sources :

Example 6 with JsonToken

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

the class JacksonGroupParser method parseDepartment.

private void parseDepartment(List<Department> list) throws Exception {
    accept(JsonToken.START_ARRAY);
    for (; ; ) {
        JsonToken tok = parser.getCurrentToken();
        if (tok == JsonToken.END_ARRAY) {
            break;
        }
        list.add(parseDepartment());
    }
    accept(JsonToken.END_ARRAY);
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken)

Example 7 with JsonToken

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

the class JacksonGroupParser method parseEmployee.

private Employee parseEmployee() throws Exception {
    accept(JsonToken.START_OBJECT);
    Employee emp = new Employee();
    for (; ; ) {
        JsonToken tok = parser.getCurrentToken();
        if (tok == JsonToken.END_OBJECT) {
            break;
        }
        if (tok == JsonToken.FIELD_NAME) {
            String name = parser.getCurrentName();
            tok = parser.nextToken();
            if ("name" == name) {
                emp.setName(acceptString(tok));
            } else if ("description" == name) {
                emp.setDescription(acceptString(tok));
            } else if ("number" == name) {
                emp.setNumber(acceptString(tok));
            } else if ("id" == name) {
                emp.setId(acceptLong(tok));
            } else if ("age" == name) {
                emp.setAge(acceptInteger(tok));
            } else if ("salary" == name) {
                emp.setSalary(acceptBigDecimal(tok));
            } else if ("birthdate" == name) {
                emp.setBirthdate(new Date(acceptLong(tok)));
            } else if ("badboy" == name) {
                emp.setBadboy(acceptBoolean(tok));
            } else {
                throw new RuntimeException("not match property : " + name);
            }
        }
    }
    accept(JsonToken.END_OBJECT);
    return emp;
}
Also used : Employee(com.alibaba.json.test.entity.Employee) JsonToken(com.fasterxml.jackson.core.JsonToken) Date(java.util.Date)

Example 8 with JsonToken

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

the class JacksonPageModelParser method parse.

/**
     * @param content
     * @throws JsonParseException
     * @throws IOException
     */
public PageInstance parse(String content) throws JsonParseException, IOException {
    JsonFactory f = new JsonFactory();
    JsonParser parser = f.createJsonParser(content);
    // move to the start of the
    JsonToken current = parser.nextToken();
    // object
    // get instanceId
    String instanceId = getNextTextValue("sid", parser);
    // get pageId
    String pageId = getNextTextValue("cid", parser);
    // move to field: segments
    current = parser.nextToken();
    assertExpectedFiled(parser.getCurrentName(), "segments", parser.getCurrentLocation());
    PageInstance pageInstance = new PageInstance();
    pageInstance.setCid(pageId);
    pageInstance.setSid(Long.valueOf(instanceId));
    pageInstance.setSegments(parseSegments(parser));
    return pageInstance;
// 构建组件树,用于递归渲染
// pageInstance.buildComponentTree();
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonToken(com.fasterxml.jackson.core.JsonToken) JsonParserHelper.assertExpectedJsonToken(com.alibaba.json.test.performance.JacksonPageModelParser.JsonParserHelper.assertExpectedJsonToken) PageInstance(com.alibaba.json.test.entity.pagemodel.PageInstance) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 9 with JsonToken

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

the class JacksonPageModelParser method parseWidgets.

/**
     * @param parser
     * @param layoutId
     * @param regionId
     * @throws JsonParseException
     * @throws IOException
     */
private List<WidgetInstance> parseWidgets(JsonParser parser, RegionEnum region) throws JsonParseException, IOException {
    JsonToken current = parser.nextToken();
    assertExpectedJsonToken(current, JsonToken.START_ARRAY, parser.getCurrentLocation());
    List<WidgetInstance> widgetInThisRegion = new ArrayList<WidgetInstance>();
    while ((current = parser.nextToken()) != JsonToken.END_ARRAY) {
        assertExpectedJsonToken(current, JsonToken.START_OBJECT, parser.getCurrentLocation());
        // get
        String instanceId = getNextTextValue("sid", parser);
        // instanceId
        // get
        String widgetId = getNextTextValue("cid", parser);
        // widgetId
        WidgetInstance widgetInstance = new WidgetInstance();
        widgetInstance.setCid(widgetId);
        widgetInstance.setSid(Long.valueOf(instanceId));
        widgetInThisRegion.add(widgetInstance);
        assertExpectedJsonToken((current = parser.nextToken()), JsonToken.END_OBJECT, parser.getCurrentLocation());
    }
    return widgetInThisRegion;
}
Also used : ArrayList(java.util.ArrayList) JsonToken(com.fasterxml.jackson.core.JsonToken) JsonParserHelper.assertExpectedJsonToken(com.alibaba.json.test.performance.JacksonPageModelParser.JsonParserHelper.assertExpectedJsonToken) WidgetInstance(com.alibaba.json.test.entity.pagemodel.WidgetInstance)

Example 10 with JsonToken

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

the class JacksonPageModelParser method parseRegions.

/**
     * @param parser
     * @param layoutId
     * @throws JsonParseException
     * @throws IOException
     */
private List<RegionInstance> parseRegions(JsonParser parser, String segment) throws JsonParseException, IOException {
    JsonToken current = parser.nextToken();
    assertExpectedJsonToken(current, JsonToken.START_ARRAY, parser.getCurrentLocation());
    List<RegionInstance> instances = new ArrayList<RegionInstance>();
    while ((current = parser.nextToken()) != JsonToken.END_ARRAY) {
        assertExpectedJsonToken(current, JsonToken.START_OBJECT, parser.getCurrentLocation());
        // get regionId
        String regionId = getNextTextValue("cid", parser);
        RegionEnum region = RegionEnum.valueOf(regionId);
        // move to field: widgtes
        current = parser.nextToken();
        assertExpectedFiled(parser.getCurrentName(), "widgets", parser.getCurrentLocation());
        RegionInstance instance = new RegionInstance();
        instance.setWidgtes(parseWidgets(parser, region));
        instances.add(instance);
        assertExpectedJsonToken((current = parser.nextToken()), JsonToken.END_OBJECT, parser.getCurrentLocation());
    }
    return instances;
}
Also used : RegionEnum(com.alibaba.json.test.entity.pagemodel.RegionEnum) ArrayList(java.util.ArrayList) JsonToken(com.fasterxml.jackson.core.JsonToken) JsonParserHelper.assertExpectedJsonToken(com.alibaba.json.test.performance.JacksonPageModelParser.JsonParserHelper.assertExpectedJsonToken) RegionInstance(com.alibaba.json.test.entity.pagemodel.RegionInstance)

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