Skip to content

Commit 25e7df7

Browse files
committed
update for merging JSONObject
1 parent 2141bdb commit 25e7df7

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.github.leonardofel</groupId>
55
<artifactId>json-java-put-null-fix</artifactId>
6-
<version>3.0.47.unsafe</version>
6+
<version>3.0.48.unsafe</version>
77
<packaging>jar</packaging>
88

99
<name>JSON in Java WITH WORKING .put(null)</name>

src/main/java/org/json/JSONObject.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,27 @@ public JSONObject update(String key, Object v2) throws JSONException {
18321832
return this;
18331833
}
18341834

1835+
public JSONObject update(JSONObject jo) throws JSONException {
1836+
final AtomicBoolean changed = new AtomicBoolean(false);
1837+
1838+
jo.forEach((key, v2) -> {
1839+
this.compute(key, (k, v1) -> {
1840+
if (Objects.equals(v1, v2) && Objects.equals(v2, v1)) {
1841+
return v1;
1842+
} else {
1843+
changed.set(true);
1844+
return JSONObject.NULL.equals(v2) ? JSONObject.NULL : v2;
1845+
}
1846+
});
1847+
});
1848+
1849+
if (changed.get()) {
1850+
this.updateListener.run();
1851+
}
1852+
1853+
return this;
1854+
}
1855+
18351856
public JSONObject synchronize(JSONObject jo) throws JSONException {
18361857
jo.forEach((key, v2) -> {
18371858
this.compute(key, (k, v1) -> {

0 commit comments

Comments
 (0)