當前位置: 首頁>>代碼示例>>Java>>正文


Java TreeNode類代碼示例

本文整理匯總了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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:RealmListNYTimesMultimediumDeserializer.java

示例2: gsonMap2Map

import com.fasterxml.jackson.core.TreeNode; //導入依賴的package包/類
/**
 * Десериализатор Gson Map в Map&lt;String, String&gt; значение
 * 
 * @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;
}
 
開發者ID:onixred,項目名稱:golos4j,代碼行數:27,代碼來源:Util.java

示例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;
}
 
開發者ID:onixred,項目名稱:golos4j,代碼行數:37,代碼來源:Util.java

示例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;
}
 
開發者ID:vianneyfaivre,項目名稱:Persephone,代碼行數:25,代碼來源:TraceService.java

示例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());
}
 
開發者ID:gameontext,項目名稱:gameon-map,代碼行數:25,代碼來源:SiteDocumentsTest.java

示例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);
  }
}
 
開發者ID:apache,項目名稱:beam,代碼行數:25,代碼來源:TestPipeline.java

示例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");
    }
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:18,代碼來源:HyperLogLogPlusJsonDeserialiser.java

示例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())));
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:25,代碼來源:CommandDeserializer.java

示例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;
}
 
開發者ID:dbmdz,項目名稱:iiif-presentation-api,代碼行數:27,代碼來源:AnnotationResourceDeserializer.java

示例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;
}
 
開發者ID:dbmdz,項目名稱:iiif-presentation-api,代碼行數:24,代碼來源:SeeAlsoDeserializer.java

示例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));
}
 
開發者ID:dbmdz,項目名稱:iiif-presentation-api,代碼行數:19,代碼來源:IiifReferenceDeserializer.java

示例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;
}
 
開發者ID:CenturyLinkCloud,項目名稱:clc-java-sdk,代碼行數:17,代碼來源:ActionSettingsDeserializer.java

示例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);
  }
}
 
開發者ID:mmmsplay10,項目名稱:QuizUpWinner,代碼行數:17,代碼來源:ObjectReader.java

示例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;
}
 
開發者ID:odiszapc,項目名稱:stem,代碼行數:18,代碼來源:Event.java

示例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;
}
 
開發者ID:lfridael,項目名稱:resourceful-java-prototype,代碼行數:17,代碼來源:ResourceDeserializer.java


注:本文中的com.fasterxml.jackson.core.TreeNode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。