4141import org .slf4j .Logger ;
4242import org .slf4j .LoggerFactory ;
4343
44- import com .fasterxml .jackson .core .JsonFactory ;
45- import com .fasterxml .jackson .core .JsonFactoryBuilder ;
46- import com .fasterxml .jackson .core .JsonParser ;
47- import com .fasterxml .jackson .core .JsonProcessingException ;
48- import com .fasterxml .jackson .core .JsonToken ;
49- import com .fasterxml .jackson .core .StreamReadFeature ;
50- import com .fasterxml .jackson .core .StreamWriteFeature ;
51- import com .fasterxml .jackson .core .json .JsonReadFeature ;
44+ import tools .jackson .core .JacksonException ;
45+ import tools .jackson .core .JsonParser ;
46+ import tools .jackson .core .JsonToken ;
47+ import tools .jackson .core .StreamReadFeature ;
48+ import tools .jackson .core .StreamWriteFeature ;
49+ import tools .jackson .core .json .JsonFactory ;
50+ import tools .jackson .core .json .JsonReadFeature ;
5251
5352/**
5453 * Abstract base class for SPARQL Results JSON Parsers. Provides a common implementation of both boolean and tuple
@@ -134,7 +133,7 @@ protected boolean parseQueryResultInternal(InputStream in, boolean attemptParseB
134133
135134 if (jp .nextToken () != JsonToken .START_OBJECT ) {
136135 throw new QueryResultParseException ("Expected SPARQL Results JSON document to start with an Object" ,
137- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getColumnNr ());
136+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getColumnNr ());
138137 }
139138
140139 List <String > varsList = new ArrayList <>();
@@ -143,27 +142,27 @@ protected boolean parseQueryResultInternal(InputStream in, boolean attemptParseB
143142
144143 while (jp .nextToken () != JsonToken .END_OBJECT ) {
145144
146- final String baseStr = jp .getCurrentName ();
145+ final String baseStr = jp .currentName ();
147146
148147 if (baseStr .equals (HEAD )) {
149148 if (jp .nextToken () != JsonToken .START_OBJECT ) {
150149 throw new QueryResultParseException ("Did not find object under " + baseStr + " field" ,
151- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getColumnNr ());
150+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getColumnNr ());
152151 }
153152
154153 while (jp .nextToken () != JsonToken .END_OBJECT ) {
155- final String headStr = jp .getCurrentName ();
154+ final String headStr = jp .currentName ();
156155
157156 if (headStr .equals (VARS )) {
158157 if (!attemptParseTuple ) {
159158 throw new QueryResultParseException (
160159 "Found tuple results variables when attempting to parse SPARQL Results JSON to boolean result" ,
161- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getLineNr ());
160+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getLineNr ());
162161 }
163162
164163 if (jp .nextToken () != JsonToken .START_ARRAY ) {
165164 throw new QueryResultParseException ("Expected variable labels to be an array" ,
166- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getColumnNr ());
165+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getColumnNr ());
167166 }
168167
169168 while (jp .nextToken () != JsonToken .END_ARRAY ) {
@@ -190,7 +189,7 @@ protected boolean parseQueryResultInternal(InputStream in, boolean attemptParseB
190189 List <String > linksList = new ArrayList <>();
191190 if (jp .nextToken () != JsonToken .START_ARRAY ) {
192191 throw new QueryResultParseException ("Expected links to be an array" ,
193- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getColumnNr ());
192+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getColumnNr ());
194193 }
195194
196195 while (jp .nextToken () != JsonToken .END_ARRAY ) {
@@ -203,48 +202,48 @@ protected boolean parseQueryResultInternal(InputStream in, boolean attemptParseB
203202
204203 } else {
205204 throw new QueryResultParseException ("Found unexpected object in head field: " + headStr ,
206- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getColumnNr ());
205+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getColumnNr ());
207206 }
208207 }
209208 } else if (baseStr .equals (RESULTS )) {
210209 if (!attemptParseTuple ) {
211210 throw new QueryResultParseException (
212211 "Found tuple results bindings when attempting to parse SPARQL Results JSON to boolean result" ,
213- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getLineNr ());
212+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getLineNr ());
214213 }
215214 if (jp .nextToken () != JsonToken .START_OBJECT ) {
216215 throw new QueryResultParseException (
217- "Found unexpected token in results object: " + jp .getCurrentName (),
218- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getColumnNr ());
216+ "Found unexpected token in results object: " + jp .currentName (),
217+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getColumnNr ());
219218 }
220219
221220 while (jp .nextToken () != JsonToken .END_OBJECT ) {
222221
223- if (jp .getCurrentName ().equals (BINDINGS )) {
222+ if (jp .currentName ().equals (BINDINGS )) {
224223 if (jp .nextToken () != JsonToken .START_ARRAY ) {
225224 throw new QueryResultParseException ("Found unexpected token in bindings object" ,
226- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getColumnNr ());
225+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getColumnNr ());
227226 }
228227
229228 while (jp .nextToken () != JsonToken .END_ARRAY ) {
230229
231230 MapBindingSet nextBindingSet = new MapBindingSet ();
232231
233- if (jp .getCurrentToken () != JsonToken .START_OBJECT ) {
232+ if (jp .currentToken () != JsonToken .START_OBJECT ) {
234233 throw new QueryResultParseException (
235- "Did not find object in bindings array: " + jp .getCurrentName (),
236- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getColumnNr ());
234+ "Did not find object in bindings array: " + jp .currentName (),
235+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getColumnNr ());
237236 }
238237
239238 while (jp .nextToken () != JsonToken .END_OBJECT ) {
240239
241- if (jp .getCurrentToken () != JsonToken .FIELD_NAME ) {
240+ if (jp .currentToken () != JsonToken .PROPERTY_NAME ) {
242241 throw new QueryResultParseException ("Did not find binding name" ,
243- jp .getCurrentLocation ().getLineNr (),
244- jp .getCurrentLocation ().getColumnNr ());
242+ jp .currentLocation ().getLineNr (),
243+ jp .currentLocation ().getColumnNr ());
245244 }
246245
247- final String bindingStr = jp .getCurrentName ();
246+ final String bindingStr = jp .currentName ();
248247
249248 nextBindingSet .addBinding (bindingStr , parseValue (jp , bindingStr ));
250249 }
@@ -266,19 +265,19 @@ protected boolean parseQueryResultInternal(InputStream in, boolean attemptParseB
266265 }
267266 // Backwards compatibility with very old draft of the original
268267 // SPARQL spec
269- else if (jp .getCurrentName ().equals (DISTINCT ) || jp .getCurrentName ().equals (ORDERED )) {
268+ else if (jp .currentName ().equals (DISTINCT ) || jp .currentName ().equals (ORDERED )) {
270269 jp .nextToken ();
271270 } else {
272271 throw new QueryResultParseException (
273- "Found unexpected field in results: " + jp .getCurrentName (),
274- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getColumnNr ());
272+ "Found unexpected field in results: " + jp .currentName (),
273+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getColumnNr ());
275274 }
276275 }
277276 } else if (baseStr .equals (BOOLEAN )) {
278277 if (!attemptParseBoolean ) {
279278 throw new QueryResultParseException (
280279 "Found boolean results when attempting to parse SPARQL Results JSON to tuple results" ,
281- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getLineNr ());
280+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getLineNr ());
282281 }
283282 jp .nextToken ();
284283
@@ -288,33 +287,33 @@ else if (jp.getCurrentName().equals(DISTINCT) || jp.getCurrentName().equals(ORDE
288287 }
289288 } else {
290289 logger .debug ("Found unexpected object in top level {} field #{}.{}" , baseStr ,
291- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getColumnNr ());
290+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getColumnNr ());
292291 // Consume the discovered unexpected object
293292 // (in particular, if it is either an array or a composite object).
294293 jp .nextToken ();
295294
296295 if (jp .currentToken () == JsonToken .START_ARRAY ) {
297- while (!(jp .getParsingContext ().getParent ().inRoot ()
296+ while (!(jp .streamReadContext ().getParent ().inRoot ()
298297 && (jp .currentToken () == JsonToken .END_ARRAY ))) {
299298 if (jp .nextToken () == null ) {
300299 throw new QueryResultParseException (
301300 "An array value of the unexpected " + baseStr + " field is not closed." ,
302- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getLineNr ());
301+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getLineNr ());
303302 }
304303 }
305304 } else if (jp .currentToken () == JsonToken .START_OBJECT ) {
306- while (!(jp .getParsingContext ().getParent ().inRoot ()
305+ while (!(jp .streamReadContext ().getParent ().inRoot ()
307306 && (jp .currentToken () == JsonToken .END_OBJECT ))) {
308307 if (jp .nextToken () == null ) {
309308 throw new QueryResultParseException (
310309 "An object value of the unexpected " + baseStr + " field is not closed." ,
311- jp .getCurrentLocation ().getLineNr (), jp .getCurrentLocation ().getLineNr ());
310+ jp .currentLocation ().getLineNr (), jp .currentLocation ().getLineNr ());
312311 }
313312 }
314313 }
315314 }
316315 }
317- } catch (JsonProcessingException e ) {
316+ } catch (JacksonException e ) {
318317 throw new QueryResultParseException ("Could not parse SPARQL/JSON" , e , e .getLocation ().getLineNr (),
319318 e .getLocation ().getLineNr ());
320319 }
@@ -325,8 +324,8 @@ else if (jp.getCurrentName().equals(DISTINCT) || jp.getCurrentName().equals(ORDE
325324 protected Value parseValue (JsonParser jp , String bindingStr ) throws IOException {
326325 if (jp .nextToken () != JsonToken .START_OBJECT ) {
327326 throw new QueryResultParseException ("Did not find object for binding value" ,
328- jp .getCurrentLocation ().getLineNr (),
329- jp .getCurrentLocation ().getColumnNr ());
327+ jp .currentLocation ().getLineNr (),
328+ jp .currentLocation ().getColumnNr ());
330329 }
331330
332331 String lang = null ;
@@ -337,42 +336,42 @@ protected Value parseValue(JsonParser jp, String bindingStr) throws IOException
337336 Triple triple = null ;
338337
339338 while (jp .nextToken () != JsonToken .END_OBJECT ) {
340- if (jp .getCurrentToken () != JsonToken .FIELD_NAME ) {
339+ if (jp .currentToken () != JsonToken .PROPERTY_NAME ) {
341340 throw new QueryResultParseException (
342341 "Did not find value attribute under " + bindingStr + " field" ,
343- jp .getCurrentLocation ().getLineNr (),
344- jp .getCurrentLocation ().getColumnNr ());
342+ jp .currentLocation ().getLineNr (),
343+ jp .currentLocation ().getColumnNr ());
345344 }
346- String fieldName = jp .getCurrentName ();
345+ String fieldName = jp .currentName ();
347346
348347 // set the appropriate state variable
349348 if (TYPE .equals (fieldName )) {
350- type = jp .nextTextValue ();
349+ type = jp .nextStringValue ();
351350 if (TRIPLE_STARDOG .equals (type )) {
352351 // Stardog RDF-star serialization dialect does not wrap the triple in a value object
353352 triple = parseStardogTripleValue (jp , type );
354353 // avoid reading away the next end-of-object token by jumping out of the loop.
355354 break ;
356355 }
357356 } else if (XMLLANG .equals (fieldName )) {
358- lang = jp .nextTextValue ();
357+ lang = jp .nextStringValue ();
359358 } else if (DATATYPE .equals (fieldName )) {
360- datatype = jp .nextTextValue ();
359+ datatype = jp .nextStringValue ();
361360 } else if (VALUE .equals (fieldName )) {
362361 if (jp .nextToken () == JsonToken .START_OBJECT ) {
363362 triple = parseTripleValue (jp , fieldName );
364- if (jp .getCurrentToken () != JsonToken .END_OBJECT ) {
365- throw new QueryResultParseException ("Unexpected token: " + jp .getCurrentName (),
366- jp .getCurrentLocation ().getLineNr (),
367- jp .getCurrentLocation ().getColumnNr ());
363+ if (jp .currentToken () != JsonToken .END_OBJECT ) {
364+ throw new QueryResultParseException ("Unexpected token: " + jp .currentName (),
365+ jp .currentLocation ().getLineNr (),
366+ jp .currentLocation ().getColumnNr ());
368367 }
369368 } else {
370369 value = jp .getText ();
371370 }
372371 } else {
373372 throw new QueryResultParseException ("Unexpected field name: " + fieldName ,
374- jp .getCurrentLocation ().getLineNr (),
375- jp .getCurrentLocation ().getColumnNr ());
373+ jp .currentLocation ().getLineNr (),
374+ jp .currentLocation ().getColumnNr ());
376375
377376 }
378377 }
@@ -387,58 +386,58 @@ private Triple parseStardogTripleValue(JsonParser jp, String fieldName) throws I
387386 Value subject = null , predicate = null , object = null ;
388387
389388 while (jp .nextToken () != JsonToken .END_OBJECT ) {
390- if (jp .getCurrentToken () != JsonToken .FIELD_NAME ) {
389+ if (jp .currentToken () != JsonToken .PROPERTY_NAME ) {
391390 throw new QueryResultParseException ("Did not find triple attribute in triple value" ,
392- jp .getCurrentLocation ().getLineNr (),
393- jp .getCurrentLocation ().getColumnNr ());
391+ jp .currentLocation ().getLineNr (),
392+ jp .currentLocation ().getColumnNr ());
394393 }
395- String posName = jp .getCurrentName ();
394+ String posName = jp .currentName ();
396395 if (SUBJECT .equals (posName )) {
397396 if (subject != null ) {
398397 throw new QueryResultParseException (
399398 posName + " field encountered twice in triple value: " ,
400- jp .getCurrentLocation ().getLineNr (),
401- jp .getCurrentLocation ().getColumnNr ());
399+ jp .currentLocation ().getLineNr (),
400+ jp .currentLocation ().getColumnNr ());
402401 }
403402 subject = parseValue (jp , fieldName + ":" + posName );
404403 } else if (PREDICATE .equals (posName )) {
405404 if (predicate != null ) {
406405 throw new QueryResultParseException (
407406 posName + " field encountered twice in triple value: " ,
408- jp .getCurrentLocation ().getLineNr (),
409- jp .getCurrentLocation ().getColumnNr ());
407+ jp .currentLocation ().getLineNr (),
408+ jp .currentLocation ().getColumnNr ());
410409 }
411410 predicate = parseValue (jp , fieldName + ":" + posName );
412411 } else if (OBJECT .equals (posName )) {
413412 if (object != null ) {
414413 throw new QueryResultParseException (
415414 posName + " field encountered twice in triple value: " ,
416- jp .getCurrentLocation ().getLineNr (),
417- jp .getCurrentLocation ().getColumnNr ());
415+ jp .currentLocation ().getLineNr (),
416+ jp .currentLocation ().getColumnNr ());
418417 }
419418 object = parseValue (jp , fieldName + ":" + posName );
420419 } else if ("g" .equals (posName )) {
421420 // silently ignore named graph field in Stardog dialect
422421 parseValue (jp , fieldName + ":" + posName );
423422 } else {
424423 throw new QueryResultParseException ("Unexpected field name in triple value: " + posName ,
425- jp .getCurrentLocation ().getLineNr (),
426- jp .getCurrentLocation ().getColumnNr ());
424+ jp .currentLocation ().getLineNr (),
425+ jp .currentLocation ().getColumnNr ());
427426 }
428427 }
429428
430429 if (subject instanceof Resource && predicate instanceof IRI && object != null ) {
431430 return valueFactory .createTriple ((Resource ) subject , (IRI ) predicate , object );
432431 } else {
433432 throw new QueryResultParseException ("Incomplete or invalid triple value" ,
434- jp .getCurrentLocation ().getLineNr (),
435- jp .getCurrentLocation ().getColumnNr ());
433+ jp .currentLocation ().getLineNr (),
434+ jp .currentLocation ().getColumnNr ());
436435 }
437436 }
438437
439438 protected Triple parseTripleValue (JsonParser jp , String fieldName ) throws IOException {
440- throw new QueryResultParseException ("Unexpected object as value" , jp .getCurrentLocation ().getLineNr (),
441- jp .getCurrentLocation ().getColumnNr ());
439+ throw new QueryResultParseException ("Unexpected object as value" , jp .currentLocation ().getLineNr (),
440+ jp .currentLocation ().getColumnNr ());
442441 }
443442
444443 protected boolean checkTripleType (JsonParser jp , String type ) {
@@ -519,13 +518,11 @@ public Collection<RioSetting<?>> getSupportedSettings() {
519518 * @return A newly configured JsonFactory based on the currently enabled settings
520519 */
521520 private JsonFactory configureNewJsonFactory () {
522- final JsonFactoryBuilder builder = new JsonFactoryBuilder ();
521+ var builder = JsonFactory . builder ();
523522 // Disable features that may work for most JSON where the field names are
524523 // in limited supply,
525524 // but does not work for SPARQL/JSON where a wide range of URIs are used for
526525 // subjects and predicates
527- builder .disable (JsonFactory .Feature .INTERN_FIELD_NAMES );
528- builder .disable (JsonFactory .Feature .CANONICALIZE_FIELD_NAMES );
529526 builder .disable (StreamWriteFeature .AUTO_CLOSE_TARGET );
530527
531528 if (getParserConfig ().isSet (JSONSettings .ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER )) {
@@ -553,7 +550,7 @@ private JsonFactory configureNewJsonFactory() {
553550 getParserConfig ().get (JSONSettings .ALLOW_UNQUOTED_CONTROL_CHARS ));
554551 }
555552 if (getParserConfig ().isSet (JSONSettings .ALLOW_UNQUOTED_FIELD_NAMES )) {
556- builder .configure (JsonReadFeature .ALLOW_UNQUOTED_FIELD_NAMES ,
553+ builder .configure (JsonReadFeature .ALLOW_UNQUOTED_PROPERTY_NAMES ,
557554 getParserConfig ().get (JSONSettings .ALLOW_UNQUOTED_FIELD_NAMES ));
558555 }
559556 if (getParserConfig ().isSet (JSONSettings .ALLOW_YAML_COMMENTS )) {
0 commit comments