@@ -328,7 +328,34 @@ S extends V> J parseObject(
328
328
JBT impliedObject ) {
329
329
330
330
return (J )parse (text , 0 , text .length (), TYPE_VALUE_OBJECT ,
331
- new ValueFactoryParseResultFacade <>(factory , null , impliedObject ));
331
+ new ValueFactoryParseResultFacade <>(
332
+ factory , null , impliedObject , null ));
333
+ }
334
+
335
+ /**
336
+ * Parse a character sequence as a JSON object. This simply calls
337
+ * {@link #parse(CharSequence, int, int, ValueType, ValueFactory)
338
+ * parse(s, 0, s.length(), EnumSet.of(ValueType.OBJECT), factory)}.
339
+ */
340
+ @ SuppressWarnings ("unchecked" ) // NOPMD
341
+ public <V ,
342
+ C extends V ,
343
+ ABT ,
344
+ A extends C ,
345
+ JBT ,
346
+ J extends C ,
347
+ B extends V ,
348
+ M extends V ,
349
+ N extends V ,
350
+ S extends V > J parseObject (
351
+ CharSequence text ,
352
+ ValueFactory <V ,C ,ABT ,A ,JBT ,J ,B ,M ,N ,S > factory ,
353
+ JBT impliedObject ,
354
+ MissingValueProvider <V > mvp ) {
355
+
356
+ return (J )parse (text , 0 , text .length (), TYPE_VALUE_OBJECT ,
357
+ new ValueFactoryParseResultFacade <>(
358
+ factory , null , impliedObject , mvp ));
332
359
}
333
360
334
361
/**
@@ -354,7 +381,36 @@ S extends V> J parseObject(
354
381
JBT impliedObject ) {
355
382
356
383
return (J )parse (text , off , length , TYPE_VALUE_OBJECT ,
357
- new ValueFactoryParseResultFacade <>(factory , null , impliedObject ));
384
+ new ValueFactoryParseResultFacade <>(
385
+ factory , null , impliedObject , null ));
386
+ }
387
+
388
+ /**
389
+ * Parse a character sequence as a JSON object. This simply calls
390
+ * {@link #parse(CharSequence, int, int, ValueType, ValueFactory)
391
+ * parse(s, off, length, EnumSet.of(ValueType.OBJECT), factory)}.
392
+ */
393
+ @ SuppressWarnings ("unchecked" )
394
+ public <V ,
395
+ C extends V ,
396
+ ABT ,
397
+ A extends C ,
398
+ JBT ,
399
+ J extends C ,
400
+ B extends V ,
401
+ M extends V ,
402
+ N extends V ,
403
+ S extends V > J parseObject (
404
+ CharSequence text ,
405
+ int off ,
406
+ int length ,
407
+ ValueFactory <V ,C ,ABT ,A ,JBT ,J ,B ,M ,N ,S > factory ,
408
+ JBT impliedObject ,
409
+ MissingValueProvider <V > mvp ) {
410
+
411
+ return (J )parse (text , off , length , TYPE_VALUE_OBJECT ,
412
+ new ValueFactoryParseResultFacade <>(
413
+ factory , null , impliedObject , mvp ));
358
414
}
359
415
360
416
/**
@@ -423,7 +479,8 @@ S extends V> A parseArray(
423
479
ABT impliedArray ) {
424
480
425
481
return (A )parse (text , 0 , text .length (), TYPE_VALUE_ARRAY ,
426
- new ValueFactoryParseResultFacade <>(factory , impliedArray , null ));
482
+ new ValueFactoryParseResultFacade <>(
483
+ factory , impliedArray , null , null ));
427
484
}
428
485
429
486
/**
@@ -449,7 +506,8 @@ S extends V> A parseArray(
449
506
ABT impliedArray ) {
450
507
451
508
return (A )parse (text , off , length , TYPE_VALUE_ARRAY ,
452
- new ValueFactoryParseResultFacade <>(factory , impliedArray , null ));
509
+ new ValueFactoryParseResultFacade <>(
510
+ factory , impliedArray , null , null ));
453
511
}
454
512
455
513
/**
@@ -537,7 +595,7 @@ S extends V> V parse(
537
595
ValueFactory <V ,C ,ABT ,A ,JBT ,J ,B ,M ,N ,S > factory ) {
538
596
return parse (text , 0 , text .length (), EnumSet .of (canReturn ), factory );
539
597
}
540
-
598
+
541
599
/**
542
600
* Parse the given JSON→URL text and return a JSON value.
543
601
* The parse will start at the character offset given by {@code off}, and
@@ -572,7 +630,7 @@ S extends V> V parse(
572
630
ValueFactory <V ,C ,ABT ,A ,JBT ,J ,B ,M ,N ,S > factory ) {
573
631
574
632
return parse (text , off , length , canReturn ,
575
- new ValueFactoryParseResultFacade <>(factory , null , null ));
633
+ new ValueFactoryParseResultFacade <>(factory , null , null , null ));
576
634
}
577
635
578
636
/**
@@ -747,7 +805,7 @@ private <R> R parse(
747
805
pos ++;
748
806
continue ;
749
807
750
- case ')' :
808
+ case END_COMPOSITE :
751
809
//
752
810
// found open paren followed by close paren; the empty
753
811
// composite value.
@@ -1141,6 +1199,14 @@ private <R> R parse(
1141
1199
pos += litlen ;
1142
1200
1143
1201
if (pos == stop ) {
1202
+ if (impliedObject && parseDepth == 1 ) {
1203
+ return result
1204
+ .setLocation (litpos )
1205
+ .addMissingValue (text , litpos , pos )
1206
+ .addObjectElement ()
1207
+ .endObject ()
1208
+ .getResult ();
1209
+ }
1144
1210
throw new SyntaxException (MSG_STILL_OPEN , pos );
1145
1211
}
1146
1212
@@ -1155,6 +1221,25 @@ private <R> R parse(
1155
1221
case NAME_SEPARATOR :
1156
1222
break ;
1157
1223
1224
+ case WFU_VALUE_SEPARATOR :
1225
+ if (!wwwFormUrlEncoded || parseDepth != 1 ) {
1226
+ throw new SyntaxException (MSG_EXPECT_OBJECT_VALUE , pos );
1227
+ }
1228
+ // fall through
1229
+ case VALUE_SEPARATOR :
1230
+ if (impliedObject && parseDepth == 1 ) {
1231
+ //
1232
+ // this may be a key that's missing a value; give
1233
+ // the result a chance to handle that case.
1234
+ //
1235
+ result
1236
+ .setLocation (litpos )
1237
+ .addMissingValue (text , litpos , pos );
1238
+
1239
+ stateStack .set (0 , State .OBJECT_AFTER_ELEMENT );
1240
+ continue ;
1241
+ }
1242
+ // fall through
1158
1243
default :
1159
1244
throw new SyntaxException (MSG_EXPECT_OBJECT_VALUE , pos );
1160
1245
}
0 commit comments