Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 2accca4

Browse files
committed
#228 Little optimization for including properties
1 parent 94fd276 commit 2accca4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/main/java/com/marklogic/mgmt/PayloadParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.util.Arrays;
1212
import java.util.Iterator;
13+
import java.util.List;
1314

1415
/**
1516
* Utility class for parsing a JSON or XML payload and extracting values.
@@ -88,13 +89,15 @@ public void setObjectMapper(ObjectMapper objectMapper) {
8889
* @return
8990
*/
9091
public String includeProperties(String payload, String... propertyNames) {
92+
List<String> propertyNameList = Arrays.asList(propertyNames);
93+
9194
if (isJsonPayload(payload)) {
9295
JsonNode json = parseJson(payload);
9396
ObjectNode node = (ObjectNode) json;
9497
Iterator<String> it = json.fieldNames();
9598
while (it.hasNext()) {
9699
String name = it.next();
97-
if (!Arrays.asList(propertyNames).contains(name)) {
100+
if (!propertyNameList.contains(name)) {
98101
it.remove();
99102
}
100103
}
@@ -104,7 +107,7 @@ public String includeProperties(String payload, String... propertyNames) {
104107
Fragment frag = new Fragment(payload);
105108
Element doc = frag.getInternalDoc().getRootElement();
106109
for (Element child : doc.getChildren()) {
107-
if (!Arrays.asList(propertyNames).contains(child.getName())) {
110+
if (!propertyNameList.contains(child.getName())) {
108111
child.detach();
109112
}
110113
}

0 commit comments

Comments
 (0)