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