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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations