本文整理汇总了Java中org.codehaus.jackson.JsonParser.readValueAsTree方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParser.readValueAsTree方法的具体用法?Java JsonParser.readValueAsTree怎么用?Java JsonParser.readValueAsTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.jackson.JsonParser
的用法示例。
在下文中一共展示了JsonParser.readValueAsTree方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
@Override
public TaskConfig deserialize(JsonParser parser,
DeserializationContext context) throws IOException {
JsonNode jsonNode = parser.readValueAsTree();
TaskConfig config = new TaskConfig();
ObjectMapper mapper;
ObjectCodec codec = parser.getCodec();
if (codec instanceof ObjectMapper) {
mapper = (ObjectMapper) codec;
} else {
mapper = new ObjectMapper();
}
if (jsonNode.has("steps")) {
Iterator<JsonNode> steps = jsonNode.get("steps").getElements();
while (steps.hasNext()) {
JsonNode next = steps.next();
if (isDtoType(next)) {
config.add(mapper.readValue(next, TaskConfigStepDto.class));
} else {
config.add(mapper.readValue(next, TaskConfigStep.class));
}
}
}
return config;
}
示例2: deserialize
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
@Override
public Mail deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException {
jsonNode = jsonParser.readValueAsTree();
return new Mail(
getValue(FROM_ADDRESS, true), getValue(TO_ADDRESS, true),
getValue(SUBJECT, false), getValue(MESSAGE, false)
);
}
示例3: getDeltaPropValue
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
private ObjectNode getDeltaPropValue(String json) {
try {
JsonFactory jf = new JsonFactory();
JsonParser jp = jf.createJsonParser(json);
ObjectMapper objMap = new ObjectMapper(jf);
jp.setCodec(objMap);
return (ObjectNode) jp.readValueAsTree();
} catch (IOException e) {
return null;
}
}
示例4: deserialize
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
@Override
public Task deserialize(JsonParser jsonParser,
DeserializationContext deserializationContext) throws IOException {
jsonNode = jsonParser.readValueAsTree();
task = new Task();
ObjectCodec codec = jsonParser.getCodec();
if (codec instanceof ObjectMapper) {
mapper = (ObjectMapper) codec;
} else {
mapper = new ObjectMapper();
}
TypeFactory typeFactory = mapper.getTypeFactory();
JavaType stringType = typeFactory.constructType(String.class);
JavaType longType = typeFactory.constructType(Long.class);
JavaType intType = typeFactory.constructType(Integer.class);
JavaType dateTime = typeFactory.constructType(DateTime.class);
JavaType booleanType = typeFactory.constructType(boolean.class);
JavaType timeType = typeFactory.constructType(Time.class);
setProperty("id", longType);
setProperty("owner", stringType);
setProperty("creator", stringType);
setProperty("creationDate", dateTime);
setProperty("modificationDate", dateTime);
setProperty("modifiedBy", stringType);
setProperty("description", stringType);
setProperty("name", stringType);
setProperty("enabled", stringType);
setProperty("hasRegisteredChannel", stringType);
setProperty("taskConfig", typeFactory.constructType(TaskConfig.class));
setProperty("trigger", typeFactory.constructType(TaskTriggerInformation.class));
setProperty("numberOfRetries", intType);
setProperty("retryIntervalInMilliseconds", intType);
setProperty("retryTaskOnFailure", stringType);
setProperty("useTimeWindow", booleanType);
setProperty("startTime", timeType);
setProperty("endTime", timeType);
setProperty(
"validationErrors",
typeFactory.constructCollectionType(Set.class, TaskError.class)
);
setProperty(
"actions",
typeFactory.constructCollectionType(List.class, TaskActionInformation.class)
);
setProperty(
"days",
typeFactory.constructCollectionType(List.class, String.class)
);
return task;
}
示例5: deserialize
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
@Override
public List<CourseUnitDto> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
JsonNode jsonNode = jsonParser.readValueAsTree();
List<CourseUnitDto> units = new ArrayList<>();
ObjectCodec codec = jsonParser.getCodec();
ObjectMapper mapper;
if (codec instanceof ObjectMapper) {
mapper = (ObjectMapper) codec;
} else {
mapper = new ObjectMapper();
}
TypeFactory typeFactory = mapper.getTypeFactory();
JavaType stringType = typeFactory.constructType(String.class);
JavaType longType = typeFactory.constructType(Long.class);
JavaType courseType = typeFactory.constructType(CourseUnitDto.class);
JavaType coursesType = typeFactory.constructCollectionType(List.class, CourseUnitDto.class);
JavaType chaptersType = typeFactory.constructCollectionType(List.class, ChapterUnitDto.class);
for (JsonNode unit : jsonNode) {
String type = mapper.readValue(unit.get("type"), stringType);
CourseUnitDto unitDto;
if (Constants.CHAPTER.equals(type)) {
unitDto = new ChapterUnitDto();
} else {
unitDto = new CourseUnitDto();
}
setProperty("id", longType, unitDto, unit, mapper);
setProperty("name", stringType, unitDto, unit, mapper);
setProperty("state", stringType, unitDto, unit, mapper);
setProperty("type", stringType, unitDto, unit, mapper);
if (Constants.COURSE.equals(type)) {
setProperty("units", chaptersType, unitDto, unit, mapper);
} else if (Constants.CHAPTER.equals(type)) {
setProperty("quiz", courseType, unitDto, unit, mapper);
setProperty("units", coursesType, unitDto, unit, mapper);
} else {
setProperty("units", coursesType, unitDto, unit, mapper);
}
units.add(unitDto);
}
return units;
}
示例6: handshake
import org.codehaus.jackson.JsonParser; //导入方法依赖的package包/类
/**
* Handshakes with the specified socket.
*
* State of the ServerConnection and supplied socket remains unchanged.
*
* @return True if successful, False if it wasn't
*/
private boolean handshake(Socket server) {
logger.trace("ENTRY ServerConnection.handshake({})", server);
if(!server.isConnected() ||
server.isInputShutdown() ||
server.isOutputShutdown()) {
logger.debug("Socket not connected.");
logger.trace("EXIT ServerConnection.handshake: {}", Boolean.FALSE);
return false;
}
// Get Hello
ObjectMapper mapper = new ObjectMapper();
JsonFactory factory = mapper.getJsonFactory();
AbstractEvent event = null;
try {
byte[] data = new byte[3000];
boolean isFinish = false;
while(!isFinish) {
if(server.getInputStream().available() > 0) {
int read = server.getInputStream().read(data);
logger.info("Read: " + Integer.toString(read));
}
else {
Thread.sleep(3000);
logger.info("Available(2): " + Integer.toString(server.getInputStream().available()));
isFinish = server.getInputStream().available() > 0 ? false : true;
}
}
JsonParser parser = factory.createJsonParser(data);
logger.info("Reading Hello");
JsonNode node = parser.readValueAsTree();
event = EventSerializer.deserialize(node);
logger.info("Received: " + event.toString());
if(event instanceof HelloEvent) {
// Send Hello
sendEvent(server, new HelloEvent(new Date()));
logger.info("Handshake PASS");
logger.trace("EXIT ServerConnection.handshake: {}", Boolean.TRUE);
return true;
}
else {
logger.info("Handshake FAIL");
logger.trace("EXIT ServerConnection.handshake: {}", Boolean.FALSE);
return false;
}
} catch(Exception e) {
e.printStackTrace();
logger.error("Catching: {}", e);
}
logger.trace("EXIT ServerConnection.handshake: {}", Boolean.TRUE);
return false;
}