@@ -95,8 +95,26 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
95
95
}
96
96
}
97
97
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 ) {
98
115
JsonFactory factory = new JsonFactory ();
99
116
factory .configure (JsonParser .Feature .ALLOW_NON_NUMERIC_NUMBERS , true );
117
+
100
118
// duplicates are handled in readValue
101
119
factory .configure (JsonParser .Feature .STRICT_DUPLICATE_DETECTION , false );
102
120
if (liberal ) {
@@ -106,12 +124,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
106
124
factory .configure (JsonParser .Feature .ALLOW_UNQUOTED_FIELD_NAMES , true );
107
125
factory .configure (JsonParser .Feature .ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER , true );
108
126
}
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 ;
115
128
}
116
129
117
130
private Sequence parse (Sequence json , String handleDuplicates , JsonFactory factory ) throws XPathException {
0 commit comments