Skip to content

Commit c1a799e

Browse files
committed
adding replacement of missing org.json methods to OrgJsonUtil
Also * replaced usages of JSONObject#toMap() and JSONArray#toList() to OrgJsonUtil#toMap() and #toList() respectively * changing the test-supporting jetty to be able to work both from jar file resources & filesystem resources (the former is needed when running the tests in android mode, the latter is for vanilla tests) * porting JSONWriter and JSONString classes from org.json
1 parent 1200da1 commit c1a799e

File tree

16 files changed

+608
-74
lines changed

16 files changed

+608
-74
lines changed

core/src/main/java/org/everit/json/schema/EnumSchema.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package org.everit.json.schema;
22

33
import static java.util.stream.Collectors.toList;
4+
import static org.everit.json.schema.loader.OrgJsonUtil.toMap;
45

5-
import java.util.Collections;
66
import java.util.ArrayList;
7-
import java.util.Objects;
7+
import java.util.Collections;
88
import java.util.List;
9+
import java.util.Objects;
910
import java.util.Set;
1011
import java.util.stream.Collectors;
12+
1113
import org.everit.json.schema.internal.JSONPrinter;
14+
import org.everit.json.schema.loader.OrgJsonUtil;
1215
import org.json.JSONArray;
1316
import org.json.JSONObject;
1417

@@ -19,9 +22,9 @@ public class EnumSchema extends Schema {
1922

2023
static Object toJavaValue(Object orig) {
2124
if (orig instanceof JSONArray) {
22-
return ((JSONArray) orig).toList();
25+
return OrgJsonUtil.toList((JSONArray) orig);
2326
} else if (orig instanceof JSONObject) {
24-
return ((JSONObject) orig).toMap();
27+
return toMap((JSONObject) orig);
2528
} else if (orig == JSONObject.NULL) {
2629
return null;
2730
} else {

core/src/main/java/org/everit/json/schema/ObjectComparator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.everit.json.schema;
22

3+
import static org.everit.json.schema.loader.OrgJsonUtil.getNames;
4+
35
import java.util.Arrays;
46
import java.util.Objects;
57

@@ -48,7 +50,7 @@ private static boolean deepEqualArrays(JSONArray arr1, JSONArray arr2) {
4850
}
4951

5052
private static String[] sortedNamesOf(JSONObject obj) {
51-
String[] raw = JSONObject.getNames(obj);
53+
String[] raw = getNames(obj);
5254
if (raw == null) {
5355
return null;
5456
}

core/src/main/java/org/everit/json/schema/ObjectSchemaValidatingVisitor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static java.lang.String.format;
44
import static java.util.Objects.requireNonNull;
5+
import static org.everit.json.schema.loader.OrgJsonUtil.getNames;
56

67
import java.util.ArrayList;
78
import java.util.List;
@@ -44,7 +45,7 @@ public ObjectSchemaValidatingVisitor(Object subject, ValidatingVisitor owner) {
4445

4546
@Override void visitPropertyNameSchema(Schema propertyNameSchema) {
4647
if (propertyNameSchema != null) {
47-
String[] names = JSONObject.getNames(objSubject);
48+
String[] names = getNames(objSubject);
4849
if (names == null || names.length == 0) {
4950
return;
5051
}
@@ -105,7 +106,7 @@ public ObjectSchemaValidatingVisitor(Object subject, ValidatingVisitor owner) {
105106
}
106107

107108
private List<String> getAdditionalProperties() {
108-
String[] names = JSONObject.getNames(objSubject);
109+
String[] names = getNames(objSubject);
109110
if (names == null) {
110111
return new ArrayList<>();
111112
} else {
@@ -129,7 +130,7 @@ private boolean matchesAnyPattern(String key) {
129130
}
130131

131132
@Override void visitPatternPropertySchema(Regexp propertyNamePattern, Schema schema) {
132-
String[] propNames = JSONObject.getNames(objSubject);
133+
String[] propNames = getNames(objSubject);
133134
if (propNames == null || propNames.length == 0) {
134135
return;
135136
}

core/src/main/java/org/everit/json/schema/internal/JSONPrinter.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
package org.everit.json.schema.internal;
22

3-
import org.everit.json.schema.Schema;
4-
import org.json.JSONWriter;
3+
import static java.util.Objects.requireNonNull;
54

65
import java.io.Writer;
76
import java.util.Map;
87

9-
import static java.util.Objects.requireNonNull;
8+
import org.everit.json.schema.Schema;
109

1110
public class JSONPrinter {
1211

1312
private final JSONWriter writer;
1413

15-
public JSONPrinter(final Writer writer) {
14+
public JSONPrinter(Writer writer) {
1615
this(new JSONWriter(writer));
1716
}
1817

19-
public JSONPrinter(final JSONWriter writer) {
18+
public JSONPrinter(org.json.JSONWriter writer) {
19+
throw new RuntimeException();
20+
}
21+
22+
public JSONPrinter(JSONWriter writer) {
2023
this.writer = requireNonNull(writer, "writer cannot be null");
2124
}
2225

0 commit comments

Comments
 (0)