Skip to content

Commit

Permalink
Merge branch 'ia-web-commons-18-multivalued-metadata'
Browse files Browse the repository at this point in the history
- adapts the upstream fix to MetaData based on com.github.openjson
  • Loading branch information
sebastian-nagel committed Nov 30, 2024
2 parents bac37c3 + f310468 commit 54e1f0d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
14 changes: 1 addition & 13 deletions src/main/java/org/archive/resource/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,7 @@ public JSONObject put(String name, long value) throws JSONException {

@Override
public JSONObject put(String key, Object value) {
if (value instanceof JSONArray) {
super.remove(key);
super.put(key, value);
} else if (has(key)) {
if (super.get(key) instanceof JSONArray) {
((JSONArray) super.get(key)).put(value);
return this;
} else {
JSONArray array = new JSONArray();
array.put(super.get(key));
array.put(value);
super.put(key, array);
}
if (has(key)) {
return super.accumulate(key, value);
}
return super.put(key, value);
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/archive/resource/MetaDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import org.archive.extract.ProducerUtils;
import org.archive.extract.ResourceFactoryMapper;
import org.archive.format.json.JSONUtils;
import org.json.JSONArray;
import org.json.JSONObject;

import com.github.openjson.JSONArray;
import com.github.openjson.JSONObject;

import junit.framework.TestCase;

Expand Down Expand Up @@ -73,8 +74,7 @@ private void verifyMultiValuedMetaData(MetaData m) {
assertEquals(1.5d, ((JSONArray) m.get("double-1")).getDouble(1));
assertEquals(2.5d, m.getDouble("double-2"));
assertEquals(3.5d, m.getDouble("double-3"));
// could be Double or BigDecimal, depending on the Java version
// assertEquals(Double.class, m.get("double-3").getClass());
assertEquals(Double.class, m.get("double-3").getClass());
assertEquals(3.5d, m.optDouble("double-3"));
assertEquals(99.5d, m.optDouble("double-99", 99.5d));

Expand Down

0 comments on commit 54e1f0d

Please sign in to comment.