@@ -271,6 +271,7 @@ public final Object read() throws IOException {
271271 case NUMBER :
272272 return readDouble ();
273273 case NULL :
274+ IterImpl .skipUntilBreak (this );
274275 return null ;
275276 case BOOLEAN :
276277 return readBoolean ();
@@ -332,7 +333,11 @@ public static final <T> T deserialize(String input, Class<T> clazz) {
332333 JsonIterator iter = tlsIter .get ();
333334 iter .reset (input .getBytes ());
334335 try {
335- return iter .read (clazz );
336+ T val = iter .read (clazz );
337+ if (IterImpl .nextToken (iter ) != 0 ) {
338+ throw iter .reportError ("deserialize" , "trailing garbage found" );
339+ }
340+ return val ;
336341 } catch (IOException e ) {
337342 throw new JsonException (e );
338343 }
@@ -342,7 +347,11 @@ public static final <T> T deserialize(String input, TypeLiteral<T> typeLiteral)
342347 JsonIterator iter = tlsIter .get ();
343348 iter .reset (input .getBytes ());
344349 try {
345- return iter .read (typeLiteral );
350+ T val = iter .read (typeLiteral );
351+ if (IterImpl .nextToken (iter ) != 0 ) {
352+ throw iter .reportError ("deserialize" , "trailing garbage found" );
353+ }
354+ return val ;
346355 } catch (IOException e ) {
347356 throw new JsonException (e );
348357 }
@@ -352,7 +361,11 @@ public static final <T> T deserialize(byte[] input, Class<T> clazz) {
352361 JsonIterator iter = tlsIter .get ();
353362 iter .reset (input );
354363 try {
355- return iter .read (clazz );
364+ T val = iter .read (clazz );
365+ if (IterImpl .nextToken (iter ) != 0 ) {
366+ throw iter .reportError ("deserialize" , "trailing garbage found" );
367+ }
368+ return val ;
356369 } catch (IOException e ) {
357370 throw new JsonException (e );
358371 }
@@ -362,7 +375,11 @@ public static final <T> T deserialize(byte[] input, TypeLiteral<T> typeLiteral)
362375 JsonIterator iter = tlsIter .get ();
363376 iter .reset (input );
364377 try {
365- return iter .read (typeLiteral );
378+ T val = iter .read (typeLiteral );
379+ if (IterImpl .nextToken (iter ) != 0 ) {
380+ throw iter .reportError ("deserialize" , "trailing garbage found" );
381+ }
382+ return val ;
366383 } catch (IOException e ) {
367384 throw new JsonException (e );
368385 }
@@ -376,7 +393,11 @@ public static final Any deserialize(byte[] input) {
376393 JsonIterator iter = tlsIter .get ();
377394 iter .reset (input );
378395 try {
379- return iter .readAny ();
396+ LazyAny val = iter .readAny ();
397+ if (IterImpl .nextToken (iter ) != 0 ) {
398+ throw iter .reportError ("deserialize" , "trailing garbage found" );
399+ }
400+ return val ;
380401 } catch (IOException e ) {
381402 throw new JsonException (e );
382403 }
0 commit comments