本文整理匯總了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;
}