Skip to content

Commit c78e9e6

Browse files
committed
Refactor JSonFactory creation
1 parent 4d9d51e commit c78e9e6

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/org/exist/xquery/functions/fn/JSON.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,26 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
9595
}
9696
}
9797

98+
JsonFactory factory = createJsonFactory(liberal);
99+
100+
if (isCalledAs("parse-json")) {
101+
return parse(args[0], handleDuplicates, factory);
102+
} else {
103+
return parseResource(args[0], handleDuplicates, factory);
104+
}
105+
}
106+
107+
/**
108+
* Create and initialize JSON factory.
109+
*
110+
* @param liberal Set TRUE to allow non standard JSON features.
111+
*
112+
* @return JSON factory
113+
*/
114+
public static JsonFactory createJsonFactory(boolean liberal) {
98115
JsonFactory factory = new JsonFactory();
99116
factory.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true);
117+
100118
// duplicates are handled in readValue
101119
factory.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, false);
102120
if (liberal) {
@@ -106,12 +124,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
106124
factory.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
107125
factory.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true);
108126
}
109-
110-
if (isCalledAs("parse-json")) {
111-
return parse(args[0], handleDuplicates, factory);
112-
} else {
113-
return parseResource(args[0], handleDuplicates, factory);
114-
}
127+
return factory;
115128
}
116129

117130
private Sequence parse(Sequence json, String handleDuplicates, JsonFactory factory) throws XPathException {

0 commit comments

Comments
 (0)