本文整理了Java中com.fasterxml.jackson.databind.node.ObjectNode.fields()
方法的一些代码示例,展示了ObjectNode.fields()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectNode.fields()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.node.ObjectNode
类名称:ObjectNode
方法名:fields
[英]Method to use for accessing all fields (with both names and values) of this JSON Object.
[中]方法用于访问此JSON对象的所有字段(包括名称和值)。
代码示例来源:origin: redisson/redisson
public ObjectCursor(JsonNode n, NodeCursor p)
{
super(JsonStreamContext.TYPE_OBJECT, p);
_contents = ((ObjectNode) n).fields();
_needEntry = true;
}
代码示例来源:origin: apache/drill
@JsonAnyGetter
public Map<String,JsonNode> _anyGetter() {
Map<String, JsonNode> unknowns = new HashMap<String, JsonNode>();
for(Iterator<Entry<String, JsonNode>> i = objectNode.fields(); i.hasNext(); ){
Entry<String, JsonNode> e = i.next();
unknowns.put(e.getKey(), e.getValue());
}
return unknowns;
}
代码示例来源:origin: atomix/atomix
@Override
public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
ObjectMapper mapper = (ObjectMapper) p.getCodec();
ObjectNode root = mapper.readTree(p);
Iterator<Map.Entry<String, JsonNode>> iterator = root.fields();
while (iterator.hasNext()) {
Map.Entry<String, JsonNode> entry = iterator.next();
if (entry.getKey().equals(TYPE_KEY)) {
Class<? extends T> configClass = concreteFactory.apply(entry.getValue().asText());
root.remove(TYPE_KEY);
return mapper.convertValue(root, configClass);
}
}
throw new ConfigurationException("Failed to deserialize polymorphic " + _valueClass.getSimpleName() + " configuration");
}
}
代码示例来源:origin: embulk/embulk
private static void mergeJsonObject(ObjectNode src, ObjectNode other) {
Iterator<Map.Entry<String, JsonNode>> ite = other.fields();
while (ite.hasNext()) {
Map.Entry<String, JsonNode> pair = ite.next();
JsonNode s = src.get(pair.getKey());
JsonNode v = pair.getValue();
if (v.isObject() && s != null && s.isObject()) {
mergeJsonObject((ObjectNode) s, (ObjectNode) v);
} else if (v.isArray() && s != null && s.isArray()) {
mergeJsonArray((ArrayNode) s, (ArrayNode) v);
} else {
src.replace(pair.getKey(), v);
}
}
}
代码示例来源:origin: knowm/XChange
ObjectNode jsonNodes = mapper.readTree(jsonParser);
Iterator<Map.Entry<String, JsonNode>> jsonNodeIterator = jsonNodes.fields();
代码示例来源:origin: embulk/embulk
@JsonCreator
private static PluginType create(final JsonNode typeJson) {
if (typeJson.isTextual()) {
return createFromString(((TextNode) typeJson).textValue());
} else if (typeJson.isObject()) {
final HashMap<String, String> stringMap = new HashMap<String, String>();
final ObjectNode typeObject = (ObjectNode) typeJson;
final Iterator<Map.Entry<String, JsonNode>> fieldIterator = typeObject.fields();
while (fieldIterator.hasNext()) {
final Map.Entry<String, JsonNode> field = fieldIterator.next();
final JsonNode fieldValue = field.getValue();
if (fieldValue instanceof ContainerNode) {
throw new IllegalArgumentException("\"type\" must be a string or a 1-depth mapping.");
}
stringMap.put(field.getKey(), fieldValue.textValue());
}
return createFromStringMap(stringMap);
} else {
throw new IllegalArgumentException("\"type\" must be a string or a 1-depth mapping.");
}
}
代码示例来源:origin: line/armeria
@Nullable
@Override
public HttpHeaders deserialize(JsonParser p, DeserializationContext ctx)
throws IOException {
final JsonNode tree = p.getCodec().readTree(p);
if (!tree.isObject()) {
ctx.reportInputMismatch(HttpHeaders.class, "HTTP headers must be an object.");
return null;
}
final ObjectNode obj = (ObjectNode) tree;
final HttpHeaders headers = HttpHeaders.of();
for (final Iterator<Entry<String, JsonNode>> i = obj.fields(); i.hasNext();) {
final Entry<String, JsonNode> e = i.next();
final AsciiString name = HttpHeaderNames.of(e.getKey());
final JsonNode values = e.getValue();
if (!values.isArray()) {
// Values is a single item, so add it directly.
addHeader(ctx, headers, name, values);
} else {
final int numValues = values.size();
for (int j = 0; j < numValues; j++) {
final JsonNode v = values.get(j);
addHeader(ctx, headers, name, v);
}
}
}
return headers.asImmutable();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
ObjectNode root = (ObjectNode) mapper.readTree(jp);
Iterator<Map.Entry<String, JsonNode>> elementsIterator =
root.fields();
DataDTO dataDTO = new DataDTO();
ExpressionDTO expressionDTO = new ExpressionDTO();
代码示例来源:origin: apache/usergrid
newHistory[history.length] = node;
ObjectNode c = ( ObjectNode ) node;
Iterator<Entry<String, JsonNode>> i = c.fields();
while ( i.hasNext() ) {
Entry<String, JsonNode> e = i.next();
代码示例来源:origin: glowroot/glowroot
public static void stripEmptyContainerNodes(ObjectNode objectNode) {
Iterator<Map.Entry<String, JsonNode>> i = objectNode.fields();
while (i.hasNext()) {
Map.Entry<String, JsonNode> entry = i.next();
JsonNode value = entry.getValue();
if (value instanceof ContainerNode && ((ContainerNode<?>) value).size() == 0) {
// remove empty nodes, e.g. unused "smtp" and "alerts" nodes
i.remove();
}
}
}
代码示例来源:origin: rakam-io/rakam
private Iterable<Map.Entry<String, JsonNode>> strip(Iterable<Map.Entry<String, JsonNode>> fields) {
ObjectNode properties = JsonHelper.jsonObject();
for (Map.Entry<String, JsonNode> entry : fields) {
String key = stripName(entry.getKey(), "property");
if (key.equals("id")) {
key = "_id";
}
properties.set(key, entry.getValue());
}
return () -> properties.fields();
}
代码示例来源:origin: glowroot/glowroot
private static ObjectNode getOrderedObjectNode(ObjectNode objectNode, List<String> keyOrder) {
Map<String, JsonNode> map = Maps.newHashMap();
Iterator<Map.Entry<String, JsonNode>> i = objectNode.fields();
while (i.hasNext()) {
Map.Entry<String, JsonNode> entry = i.next();
map.put(entry.getKey(), entry.getValue());
}
ObjectNode orderedObjectNode = mapper.createObjectNode();
for (Map.Entry<String, JsonNode> entry : new ExplicitOrdering(keyOrder)
.sortedCopy(map.entrySet())) {
orderedObjectNode.set(entry.getKey(), entry.getValue());
}
return orderedObjectNode;
}
代码示例来源:origin: rakam-io/rakam
@Override
public void setUserProperties(String project, Object userId, ObjectNode properties) {
try (Connection conn = queryExecutor.getConnection()) {
setUserProperties(conn, project, userId, () -> properties.fields(), false);
} catch (SQLException e) {
throw Throwables.propagate(e);
}
}
代码示例来源:origin: rakam-io/rakam
@Override
public void setUserPropertiesOnce(String project, Object userId, ObjectNode properties) {
try (Connection conn = queryExecutor.getConnection()) {
setUserProperties(conn, project, userId, () -> properties.fields(), true);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: rakam-io/rakam
@Override
public Object create(String project, Object id, ObjectNode properties) {
try (Connection conn = queryExecutor.getConnection()) {
return createInternal(conn, project, id, () -> properties.fields());
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: opensourceBIM/BIMserver
private void cleanup() {
Iterator<Entry<String, JsonNode>> fields = definesNode.fields();
while (fields.hasNext()) {
Entry<String, JsonNode> entry = fields.next();
if (entry.getValue().get("fields").size() == 0) {
fields.remove();
}
}
fields = definesNode.fields();
while (fields.hasNext()) {
Entry<String, JsonNode> entry = fields.next();
ArrayNode includes = (ArrayNode) entry.getValue().get("includes");
Iterator<JsonNode> includesIterator = includes.iterator();
while (includesIterator.hasNext()) {
JsonNode includeNode = includesIterator.next();
if (!definesNode.has(includeNode.asText())) {
// TODO replace the include with the closest super-type? Or don't allow deleting defines that are explicitly referenced (although no fields)
includesIterator.remove();
}
}
}
}
代码示例来源:origin: rakam-io/rakam
private Map<String, AttributeValue> generatePutRequest(String project, Object id, ObjectNode properties) {
Map<String, AttributeValue> builder = new HashMap<>();
builder.put("project", new AttributeValue(project));
builder.put("id", new AttributeValue(id.toString()));
Map<String, AttributeValue> props = new HashMap<>();
Iterator<Entry<String, JsonNode>> fields = properties.fields();
while (fields.hasNext()) {
Entry<String, JsonNode> next = fields.next();
props.put(next.getKey(), convertAttributeValue(next.getValue()));
}
builder.put("properties", new AttributeValue().withM(props));
return builder;
}
代码示例来源:origin: briandilley/jsonrpc4j
private void collectVarargsFromNode(JsonNode node) {
if (node.isArray()) {
ArrayNode arrayNode = ArrayNode.class.cast(node);
for (int i = 0; i < node.size(); i++) {
addArgument(arrayNode.get(i));
}
}
if (node.isObject()) {
ObjectNode objectNode = ObjectNode.class.cast(node);
Iterator<Map.Entry<String,JsonNode>> items = objectNode.fields();
while (items.hasNext()) {
Map.Entry<String,JsonNode> item = items.next();
JsonNode name = JsonNodeFactory.instance.objectNode().put(item.getKey(),item.getKey());
addArgument(name.get(item.getKey()));
addArgument(item.getValue());
}
}
}
代码示例来源:origin: opensourceBIM/BIMserver
private void parseProperties(QueryPart queryPart, ObjectNode properties) throws QueryException {
Iterator<Entry<String, JsonNode>> fields = properties.fields();
while (fields.hasNext()) {
Entry<String, JsonNode> entry = fields.next();
if (value.isObject()) {
ObjectNode set = (ObjectNode)value;
Iterator<Entry<String, JsonNode>> propertySetFields = set.fields();
while (propertySetFields.hasNext()) {
Entry<String, JsonNode> propertyEntry = propertySetFields.next();
代码示例来源:origin: spring-projects/spring-data-rest
Iterator<Entry<String, JsonNode>> fields = node.fields();
Class<?> keyType = typeOrObject(type.getComponentType());
TypeInformation<?> valueType = type.getMapValueType();
内容来源于网络,如有侵权,请联系作者删除!