本文整理匯總了Java中com.fasterxml.jackson.core.TreeNode類的典型用法代碼示例。如果您正苦於以下問題:Java TreeNode類的具體用法?Java TreeNode怎麽用?Java TreeNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TreeNode類屬於com.fasterxml.jackson.core包,在下文中一共展示了TreeNode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deserialize
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
@Override
public List<NYTimesMultimedium> deserialize(JsonParser parser, DeserializationContext context) throws IOException {
RealmList<NYTimesMultimedium> list = new RealmList<>();
TreeNode treeNode = parser.getCodec().readTree(parser);
if (!(treeNode instanceof ArrayNode)) {
return list;
}
ArrayNode arrayNode = (ArrayNode) treeNode;
for (JsonNode node : arrayNode) {
NYTimesMultimedium nyTimesMultimedium =
objectMapper.treeToValue(node, NYTimesMultimedium.class);
list.add(nyTimesMultimedium);
}
return list;
}
示例2: gsonMap2Map
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
/**
* Десериализатор Gson Map в Map<String, String> значение
*
* @param parser
* Gson строка
* @throws IOException
* исключение парсера
* @return карта
*/
public static Map<String, String> gsonMap2Map(JsonParser parser) throws IOException {
ObjectCodec codec = parser.getCodec();
TreeNode node = codec.readTree(parser);
Map<String, String> ret = new HashMap<String, String>();
if (node.isObject()) {
for (Iterator<String> iter = node.fieldNames(); iter.hasNext();) {
String fieldName = iter.next();
TreeNode field = node.get(fieldName);
if (field != null) {
ret.put(fieldName, field.toString());
} else {
ret.put(fieldName, "null");
}
}
}
return ret;
}
示例3: string2Map
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
/**
* Десериализатор TreeNode массива в Map где четный элемент ключ а не четный
* значение
*
* @param <T>
* тип ключя карты
* @param <V>
* тип значения карты
* @param node
* узел
* @param keyClass
* класс для ключа карты
* @param valueClass
* класс для значения карты
* @throws IOException
* исключение парсера
* @return карта
*/
private static <T, V> Map<T, V> string2Map(TreeNode node, Class<T> keyClass, Class<V> valueClass)
throws IOException {
ObjectMapper mapper = new ObjectMapper();
Map<T, V> ret = new HashMap<T, V>();
if (node.isArray()) {
T key = null;
ArrayNode key2value = (ArrayNode) node;
for (int i = 0; i < key2value.size(); i++) {
if (i % 2 == 0) {
key = mapper.treeToValue(key2value.get(i), keyClass);
} else {
V value = mapper.treeToValue(key2value.get(i), valueClass);
ret.put(key, value);
}
}
}
return ret;
}
示例4: parse
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
private Map<String, List<String>> parse(TreeNode node) {
Map<String, List<String>> result = new HashMap<>();
Iterator<String> itKeys = node.fieldNames();
while(itKeys.hasNext()) {
String key = itKeys.next();
List<String> values = new ArrayList<>();
// Header has only one value
if(node.get(key).isValueNode()) {
values.add(((JsonNode)node.get(key)).asText());
}
// Header has multiple values
else if (node.get(key).isArray()){
for (JsonNode val : (JsonNode) node.get(key)) {
values.add(val.asText());
}
}
result.put(key, values);
}
return result;
}
示例5: testGetExits
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
@Test
public void testGetExits(@Mocked ViewResult queryResult, @Mocked ViewResult.Row row, @Mocked JsonNode key) throws Exception {
List<ViewResult.Row> rows = Arrays.asList(row);
Exits exits = new Exits();
exits.setN(new Exit(site, "n"));
site.setExits(exits);
final ObjectMapper anyInstance = new ObjectMapper();
new Expectations(ObjectMapper.class) {{
anyInstance.treeToValue((TreeNode) any, Site.class); returns(site);
}};
new Expectations() {{
dbc.queryView((ViewQuery) any); returns(queryResult);
queryResult.getRows(); returns(rows);
row.getKeyAsNode(); returns(key);
key.get(2); returns(JsonNodeFactory.instance.textNode("n"));
}};
Exits e = docs.getExits(new Coordinates(1,2));
Assert.assertEquals("Site should be bound to the north", site.getId(), e.getN().getId());
}
示例6: convertToArgs
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
public static String[] convertToArgs(PipelineOptions options) {
try {
byte[] opts = MAPPER.writeValueAsBytes(options);
JsonParser jsonParser = MAPPER.getFactory().createParser(opts);
TreeNode node = jsonParser.readValueAsTree();
ObjectNode optsNode = (ObjectNode) node.get("options");
ArrayList<String> optArrayList = new ArrayList<>();
Iterator<Entry<String, JsonNode>> entries = optsNode.fields();
while (entries.hasNext()) {
Entry<String, JsonNode> entry = entries.next();
if (entry.getValue().isNull()) {
continue;
} else if (entry.getValue().isTextual()) {
optArrayList.add("--" + entry.getKey() + "=" + entry.getValue().asText());
} else {
optArrayList.add("--" + entry.getKey() + "=" + entry.getValue());
}
}
return optArrayList.toArray(new String[optArrayList.size()]);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
示例7: deserialize
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
@Override
public HyperLogLogPlus deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
final TreeNode coreHyperLogLogPlusObject = treeNode.get("hyperLogLogPlus");
if (null != coreHyperLogLogPlusObject) {
final TextNode jsonNodes = (TextNode) coreHyperLogLogPlusObject.get(HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SKETCH_BYTES_FIELD);
final byte[] nodeAsString = jsonNodes.binaryValue();
final HyperLogLogPlus hyperLogLogPlus = HyperLogLogPlus.Builder.build(nodeAsString);
return hyperLogLogPlus;
} else {
throw new IllegalArgumentException("Receieved null or empty HyperLogLogPlus sketch");
}
}
示例8: deserialize
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
/**
* Parse command field from the compose yaml file to list command words.
*
* @param jsonParser json parser
* @param ctxt deserialization context
* @throws IOException in case I/O error. For example element to parsing contains invalid yaml
* field type defined for this field by yaml document model.
* @throws JsonProcessingException
*/
@Override
public List<String> deserialize(JsonParser jsonParser, DeserializationContext ctxt)
throws IOException {
TreeNode tree = jsonParser.readValueAsTree();
if (tree.isArray()) {
return toCommand((ArrayNode) tree, ctxt);
}
if (tree instanceof TextNode) {
TextNode textNode = (TextNode) tree;
return asList(textNode.asText().trim().split(SPLIT_COMMAND_REGEX));
}
throw ctxt.mappingException(
(format("Field '%s' must be simple text or string array.", jsonParser.getCurrentName())));
}
示例9: deserialize
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
@Override
public AnnotationResource deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
AnnotationResource result;
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
TreeNode node = mapper.readTree(jp);
String format = ((TextNode) node.get("format")).textValue();
String id = null;
TextNode idNode = (TextNode) node.get("@id");
if (idNode != null) {
id = idNode.textValue();
}
String type = ((TextNode) node.get("@type")).textValue();
if (node.get("chars") != null) {
result = new AnnotationResourceCharsImpl(type, format);
String chars = ((TextNode) node.get("chars")).textValue();
((AnnotationResourceCharsImpl) result).setChars(chars);
} else {
result = new AnnotationResourceImpl(type, format);
}
if (id != null) {
result.setId(URI.create(id));
}
return result;
}
示例10: deserialize
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
@Override
public SeeAlso deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
TreeNode node = mapper.readTree(jp);
SeeAlso seeAlso = new SeeAlsoImpl();
if (ObjectNode.class.isAssignableFrom(node.getClass())) {
String id = ((TextNode) node.get("@id")).textValue();
TextNode formatNode = ((TextNode) node.get("format"));
TextNode profileNode = ((TextNode) node.get("profile"));
seeAlso.setId(uriFromString(id));
if (formatNode != null) {
seeAlso.setFormat(formatNode.textValue());
}
if (profileNode != null) {
seeAlso.setProfile(uriFromString(profileNode.textValue()));
}
} else if (TextNode.class.isAssignableFrom(node.getClass())) {
seeAlso.setId(uriFromString(((TextNode) node).textValue()));
} else {
throw new IllegalArgumentException("SeeAlso must be a string or object!");
}
return seeAlso;
}
示例11: deserialize
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
@Override
public IiifReference deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
TreeNode node = mapper.readTree(jp);
String id;
if (ObjectNode.class.isAssignableFrom(node.getClass())) {
id = ((TextNode) node.get("@id")).textValue();
String type = ((TextNode) node.get("@type")).textValue();
if (!"sc:AnnotationList".equals(type)) {
throw new IllegalArgumentException(String.format("Do not know how to handle reference type '%s'", type));
}
} else if (TextNode.class.isAssignableFrom(node.getClass())) {
id = ((TextNode) node).textValue();
} else {
throw new IllegalArgumentException("Reference must be a string or object!");
}
return new AnnotationListReferenceImpl(URI.create(id));
}
示例12: deserialize
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
@Override
public ActionSettingsMetadata deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException {
TreeNode node = jsonParser.getCodec().readTree(jsonParser);
//email settings
if (node.get(RECIPIENTS).isArray()) {
ArrayNode recipientsNode = ((ArrayNode)node.get(RECIPIENTS));
List<String> recipients = new ArrayList<>(recipientsNode.size());
recipientsNode.forEach(recipient -> recipients.add(recipient.asText()));
return new ActionSettingsEmailMetadata().recipients(recipients);
}
return null;
}
示例13: treeToValue
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
public <T> T treeToValue(TreeNode paramTreeNode, Class<T> paramClass)
{
try
{
Object localObject = readValue(treeAsTokens(paramTreeNode), paramClass);
return localObject;
}
catch (JsonProcessingException localJsonProcessingException)
{
throw localJsonProcessingException;
}
catch (IOException localIOException)
{
throw new IllegalArgumentException(localIOException.getMessage(), localIOException);
}
}
示例14: deserialize
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
@Override
public Event deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
ObjectCodec codec = jp.getCodec();
TreeNode treeNode = codec.readTree(jp);
UUID id = UUID.fromString(((TextNode) treeNode.get("id")).asText());
String typeStr = ((TextNode) treeNode.get("type")).asText();
Type type = Type.byName(typeStr);
TreeNode responseNode = treeNode.get("response");
StemResponse result = mapper.treeToValue(responseNode, type.clazz);
Event event = Event.create(type, id);
event.setResponse(result);
return event;
}
示例15: deserialize
import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
@Override
public Resource deserialize(JsonParser parser, DeserializationContext context) throws IOException {
TreeNode tree = parser.readValueAsTree();
Assert.isTrue(tree.path("rClass") != MissingNode.getInstance(),
"No 'rClass' field found. Cannot deserialize Resource JSON.");
RClass rClass = modelService.resolveRType(((TextNode) tree.path("rClass")).textValue());
if (rClass.isAbstract()) {
throw new AbstractRClassException(rClass);
}
Resource resource = factory.createResource(rClass);
TreeNode properties = tree.path("properties");
if (properties instanceof ObjectNode) {
populateProperties((ObjectNode) properties, resource);
}
return resource;
}