Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for-each loops with object nodes #1590

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/com/fasterxml/jackson/databind/JsonNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ public Iterator<String> fieldNames() {
return ClassUtil.emptyIterator();
}

@Override
public Set<String> fieldNamesSet() {
return Collections.emptySet();
}

/**
* Method for locating node specified by given JSON pointer instances.
* Method will never return null; if no matching node exists,
Expand Down Expand Up @@ -770,6 +775,14 @@ public Iterator<Map.Entry<String, JsonNode>> fields() {
return ClassUtil.emptyIterator();
}

/**
* @return Set that can be used to traverse all key/value pairs for
* object nodes; empty set (no contents) for other types
*/
public Set<Map.Entry<String, JsonNode>> fieldSet() {
return Collections.emptySet();
}

/*
/**********************************************************
/* Public API, find methods
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/fasterxml/jackson/databind/node/ObjectNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public Iterator<String> fieldNames() {
return _children.keySet().iterator();
}

@Override
public Set<String> fieldNamesSet() {
return _children.keySet();
}

@Override
public JsonNode path(int index) {
return MissingNode.getInstance();
Expand All @@ -126,6 +131,15 @@ public Iterator<Map.Entry<String, JsonNode>> fields() {
return _children.entrySet().iterator();
}

/**
* Method to use for accessing all fields (with both names
* and values) of this JSON Object.
*/
@Override
public Set<Map.Entry<String, JsonNode>> fieldSet() {
return _children.entrySet();
}

@Override
public ObjectNode with(String propertyName) {
JsonNode n = _children.get(propertyName);
Expand Down