本文整理匯總了Java中com.fasterxml.jackson.core.ObjectCodec.treeToValue方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectCodec.treeToValue方法的具體用法?Java ObjectCodec.treeToValue怎麽用?Java ObjectCodec.treeToValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.fasterxml.jackson.core.ObjectCodec
的用法示例。
在下文中一共展示了ObjectCodec.treeToValue方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deserialize
import com.fasterxml.jackson.core.ObjectCodec; //導入方法依賴的package包/類
/**
* Deserialize the node field list item.
*
* @param jsonNode
* Node which represents the node field list item.
* @param jsonParser
* @return Deserialized field list item.
* @throws JsonProcessingException
*/
public NodeFieldListItem deserialize(JsonNode jsonNode, JsonParser jsonParser) throws JsonProcessingException {
ObjectCodec oc = jsonParser.getCodec();
NodeResponse nodeItem = null;
try {
// Try to deserialize the node response in the expanded form.
nodeItem = JsonUtil.readValue(jsonNode.toString(), NodeResponse.class);
} catch (GenericRestException e) {
// Fallback and deseralize the element using the collapsed form.
NodeFieldListItemImpl collapsedItem = oc.treeToValue(jsonNode, NodeFieldListItemImpl.class);
nodeItem = new NodeResponse();
nodeItem.setUuid(collapsedItem.getUuid());
}
return nodeItem;
}
示例2: deserialize
import com.fasterxml.jackson.core.ObjectCodec; //導入方法依賴的package包/類
@Override
public CustomIndicator deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
List<String> indicatorFields = getDeclaredFields();
ObjectCodec oc = p.getCodec();
ObjectNode node = oc.readTree(p);
CustomIndicator obj = new CustomIndicator(oc.treeToValue(node, Indicator.class));
Map<String, String> map = new HashMap<String, String>();
//indicator specific fields
Iterator<String> keys = node.fieldNames();
while( keys.hasNext() ) {
String key = (String)keys.next();
String value = node.get(key).textValue();
if(!indicatorFields.contains(key)) {
map.put(key, value);
}
}
obj.setMap(map);
return obj;
}
示例3: deserialize
import com.fasterxml.jackson.core.ObjectCodec; //導入方法依賴的package包/類
@Override
public GenericIndicatorResponseData deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
GenericIndicatorResponseData result = new GenericIndicatorResponseData();
ObjectCodec oc = p.getCodec();
ObjectNode rootNode = oc.readTree(p);
Iterator<String> keys = rootNode.fieldNames();
if (keys.hasNext()) {
String key = (String) keys.next();
//result.setType(key);
JsonNode value = rootNode.get(key);
CustomIndicator obj = oc.treeToValue(value, CustomIndicator.class);
//obj.setType(key);
obj.setIndicatorType(key);
//result.setCustomIndicator(obj);
}
return result;
}
開發者ID:ThreatConnect-Inc,項目名稱:threatconnect-java,代碼行數:20,代碼來源:GenericIndicatorResponseDataDeserializer.java
示例4: deserialize
import com.fasterxml.jackson.core.ObjectCodec; //導入方法依賴的package包/類
@Override
public CustomIndicatorResponseData deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
CustomIndicatorResponseData result = new CustomIndicatorResponseData();
ObjectCodec oc = p.getCodec();
ObjectNode rootNode = oc.readTree(p);
Iterator<String> keys = rootNode.fieldNames();
if (keys.hasNext()) {
String key = (String) keys.next();
result.setType(key);
JsonNode value = rootNode.get(key);
CustomIndicator obj = oc.treeToValue(value, CustomIndicator.class);
//obj.setType(key);
obj.setIndicatorType(key);
result.setCustomIndicator(obj);
}
return result;
}
開發者ID:ThreatConnect-Inc,項目名稱:threatconnect-java,代碼行數:20,代碼來源:CustomIndicatorResponseDataDeserializer.java
示例5: doDeserialize
import com.fasterxml.jackson.core.ObjectCodec; //導入方法依賴的package包/類
@Override
public FieldTitle doDeserialize(ObjectCodec oc, JsonNode node, JsonParser jp, DeserializationContext ctxt) throws IOException {
FieldTitle ft = new FieldTitle();
JsonNode key = node.get("key");
ft.setKey(key.textValue());
// Set title
JsonNode title = node.get("title");
if(title == null) {
title = node.get("&title");
}
TranslationObject loc = null;
if(title != null) {
loc = oc.treeToValue(title, TranslationObject.class);
}
ft.setTitle(loc);
return ft;
}
示例6: deserialize
import com.fasterxml.jackson.core.ObjectCodec; //導入方法依賴的package包/類
@SuppressWarnings("DuplicateThrows")
@Override
public LogEntry deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
ObjectCodec codec = parser.getCodec();
JsonNode logEntryNode = codec.readTree(parser);
long index = logEntryNode.get(LOG_ENTRY_INDEX_FIELD).asLong();
long term = logEntryNode.get(LOG_ENTRY_TERM_FIELD).asLong();
String stringType = logEntryNode.get(LOG_ENTRY_TYPE_FIELD).textValue();
if (stringType.equals(LogEntry.Type.NOOP.name())) {
return new LogEntry.NoopEntry(index, term);
} else if (stringType.equals(LogEntry.Type.CLIENT.name())) {
JsonNode commandNode = logEntryNode.get(CLIENT_ENTRY_COMMAND_FIELD);
Command command = codec.treeToValue(commandNode, Command.class);
return new LogEntry.ClientEntry(index, term, command);
} else if (stringType.equals(LogEntry.Type.CONFIGURATION.name())) {
return new LogEntry.ConfigurationEntry(index, term, Sets.<String>newHashSet(), Sets.<String>newHashSet());
} else {
throw new JsonMappingException("unknown type " + stringType);
}
}
示例7: deserialize
import com.fasterxml.jackson.core.ObjectCodec; //導入方法依賴的package包/類
@Override
public ExpandableNode deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
// Only the node reference impl version has a project name property.
if (node.has("projectName")) {
NodeReference basicReference = oc.treeToValue(node, NodeReference.class);
return basicReference;
} else {
NodeResponse expandedField = JsonUtil.readValue(node.toString(), NodeResponse.class);
return expandedField;
}
}
示例8: deserialize
import com.fasterxml.jackson.core.ObjectCodec; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public TaggedBucketPoint deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
ObjectCodec objectCodec = jp.getCodec();
JsonNode node = objectCodec.readTree(jp);
JsonNode tagsJsonNode = node.get("tags");
JsonNode minJsonNode = node.get("min");
JsonNode avgJsonNode = node.get("avg");
JsonNode medianJsonNode = node.get("median");
JsonNode maxJsonNode = node.get("max");
JsonNode sumJsonNode = node.get("sum");
JsonNode samplesJsonNode = node.get("samples");
JsonNode percentilesJsonNode = node.get("percentiles");
List<Percentile> percentiles = new ArrayList<Percentile>();
if (percentilesJsonNode != null) {
percentiles = objectCodec.treeToValue(percentilesJsonNode, List.class);
}
return new TaggedBucketPoint(tagsJsonNode == null ? new HashMap<String, String>() : objectCodec.treeToValue(tagsJsonNode, Map.class),
minJsonNode == null ? 0 : minJsonNode.asDouble(),
avgJsonNode == null ? 0 : avgJsonNode.asDouble(),
medianJsonNode == null ? 0 : medianJsonNode.asDouble(),
maxJsonNode == null ? 0 : maxJsonNode.asDouble(),
sumJsonNode == null ? 0 : sumJsonNode.asDouble(),
samplesJsonNode == null ? 0 : samplesJsonNode.asInt(),
percentiles);
}
示例9: deserialize
import com.fasterxml.jackson.core.ObjectCodec; //導入方法依賴的package包/類
public Object deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
String resultType = node.get("type").asText();
try {
Class type = Class.forName(resultType) ;
JsonNode rnode = node.get("data") ;
Object val = oc.treeToValue(rnode, type);
return val ;
} catch (ClassNotFoundException e) {
throw new IOException(e) ;
}
}
示例10: doDeserialize
import com.fasterxml.jackson.core.ObjectCodec; //導入方法依賴的package包/類
@Override
protected Option doDeserialize(ObjectCodec oc, JsonNode node, JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonNode value = node.get("value");
if(value == null || value.getNodeType() == JsonNodeType.NULL) {
return null;
}
Option o = new Option(value.textValue());
// Set deprecated
JsonNode dep = node.get("deprecated");
if(dep != null && dep.getNodeType() != JsonNodeType.NULL) {
o.setDeprecated(dep.asBoolean());
}
// Set title
JsonNode title = node.get("title");
if(title == null) {
title = node.get("&title");
}
TranslationObject loc = null;
if(title != null) {
loc = oc.treeToValue(title, TranslationObject.class);
}
o.setTitle(loc);
return o;
}
示例11: deserialize
import com.fasterxml.jackson.core.ObjectCodec; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public NumericBucketPoint deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
ObjectCodec objectCodec = jp.getCodec();
JsonNode node = objectCodec.readTree(jp);
long start = 0L;
JsonNode startJsonNode = node.get("start");
if (startJsonNode != null) {
start = startJsonNode.asLong();
}
long end = 0L;
JsonNode endJsonNode = node.get("end");
if (endJsonNode != null) {
end = endJsonNode.asLong();
}
JsonNode minJsonNode = node.get("min");
JsonNode avgJsonNode = node.get("avg");
JsonNode medianJsonNode = node.get("median");
JsonNode maxJsonNode = node.get("max");
JsonNode sumJsonNode = node.get("sum");
JsonNode samplesJsonNode = node.get("samples");
JsonNode percentilesJsonNode = node.get("percentiles");
List<Percentile> percentiles = new ArrayList<Percentile>();
if (percentilesJsonNode != null) {
percentiles = objectCodec.treeToValue(percentilesJsonNode, List.class);
}
return new NumericBucketPoint.Builder(start, end)
.setMin(minJsonNode == null ? 0 : minJsonNode.asDouble())
.setAvg(avgJsonNode == null ? 0 : avgJsonNode.asDouble())
.setMedian(medianJsonNode == null ? 0 : medianJsonNode.asDouble())
.setMax(maxJsonNode == null ? 0 : maxJsonNode.asDouble())
.setSum(sumJsonNode == null ? 0 : sumJsonNode.asDouble())
.setSamples(samplesJsonNode == null ? 0 : samplesJsonNode.asInt())
.setPercentiles(percentiles)
.build();
}
示例12: doDeserialize
import com.fasterxml.jackson.core.ObjectCodec; //導入方法依賴的package包/類
@Override
public Button doDeserialize(ObjectCodec oc, JsonNode node, JsonParser jp, DeserializationContext ctxt) throws IOException {
Button btn = new Button();
// Set title
JsonNode title = node.get("title");
if(title == null) {
title = node.get("&title");
}
TranslationObject loc = null;
if(title != null) {
loc = oc.treeToValue(title, TranslationObject.class);
}
btn.setTitle(loc);
// Set referenceIsHandledByUser
JsonNode isHandledByUser = node.get("isHandledByUser");
if(isHandledByUser != null && isHandledByUser.getNodeType() == JsonNodeType.STRING) {
btn.setIsHandledByUser(isHandledByUser.textValue());
}
// Set isHandler
JsonNode handler = node.get("isHandler");
if(handler != null && handler.getNodeType() == JsonNodeType.BOOLEAN) {
btn.setIsHandler(handler.booleanValue());
}
// Set hasHandler
handler = node.get("hasHandler");
if(handler != null && handler.getNodeType() == JsonNodeType.BOOLEAN) {
btn.setHasHandler(handler.booleanValue());
}
// Set user groups
JsonNode groups = node.get("permissions");
if(groups != null && groups.getNodeType() == JsonNodeType.ARRAY) {
for(JsonNode group : groups) {
if(group.getNodeType() == JsonNodeType.STRING) {
btn.getPermissions().add(group.textValue());
}
}
}
// Set type
JsonNode type = node.get("type");
if(type != null && type.getNodeType() == JsonNodeType.STRING) {
btn.setType(ButtonType.valueOf(type.textValue()));
}
// Set states
JsonNode states = node.get("states");
if(states != null && states.getNodeType() == JsonNodeType.ARRAY) {
for(JsonNode state : states) {
if(state.getNodeType() == JsonNodeType.STRING) {
btn.getStates().add(VisibilityState.valueOf(state.textValue()));
}
}
}
JsonNode customHandler = node.get("customHandler");
if(customHandler != null && customHandler.getNodeType() == JsonNodeType.STRING) {
btn.setCustomHandler(customHandler.textValue());
}
return btn;
}
示例13: deserialize
import com.fasterxml.jackson.core.ObjectCodec; //導入方法依賴的package包/類
@SuppressWarnings("DuplicateThrows")
@Override
public CommandSubclass deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
ObjectCodec codec = parser.getCodec();
return codec.treeToValue(parser.readValueAsTree(), commandSubclassKlass);
}