@@ -345,7 +345,6 @@ public JsonToken nextToken() throws IOException
345
345
{
346
346
_currentIsAlias = false ;
347
347
_binaryValue = null ;
348
- _currentAnchor = null ;
349
348
if (_closed ) {
350
349
return null ;
351
350
}
@@ -363,33 +362,37 @@ public JsonToken nextToken() throws IOException
363
362
}
364
363
// is null ok? Assume it is, for now, consider to be same as end-of-doc
365
364
if (evt == null ) {
365
+ _currentAnchor = null ;
366
366
return (_currToken = null );
367
367
}
368
368
_lastEvent = evt ;
369
-
370
- /* One complication: field names are only inferred from the
371
- * fact that we are in Object context...
372
- */
373
- if (_parsingContext .inObject () && _currToken != JsonToken .FIELD_NAME ) {
374
- if (!evt .is (Event .ID .Scalar )) {
375
- // end is fine
376
- if (evt .is (Event .ID .MappingEnd )) {
377
- if (!_parsingContext .inObject ()) { // sanity check is optional, but let's do it for now
378
- _reportMismatchedEndMarker ('}' , ']' );
369
+
370
+ // One complication: field names are only inferred from the
371
+ // fact that we are in Object context...
372
+ if (_parsingContext .inObject ()) {
373
+ if (_currToken != JsonToken .FIELD_NAME ) {
374
+ if (!evt .is (Event .ID .Scalar )) {
375
+ _currentAnchor = null ;
376
+ // end is fine
377
+ if (evt .is (Event .ID .MappingEnd )) {
378
+ if (!_parsingContext .inObject ()) { // sanity check is optional, but let's do it for now
379
+ _reportMismatchedEndMarker ('}' , ']' );
380
+ }
381
+ _parsingContext = _parsingContext .getParent ();
382
+ return (_currToken = JsonToken .END_OBJECT );
379
383
}
380
- _parsingContext = _parsingContext .getParent ();
381
- return (_currToken = JsonToken .END_OBJECT );
384
+ _reportError ("Expected a field name (Scalar value in YAML), got this instead: " +evt );
382
385
}
383
- _reportError ("Expected a field name (Scalar value in YAML), got this instead: " +evt );
386
+ ScalarEvent scalar = (ScalarEvent ) evt ;
387
+ String name = scalar .getValue ();
388
+ _currentFieldName = name ;
389
+ _parsingContext .setCurrentName (name );
390
+ _currentAnchor = scalar .getAnchor ();
391
+ return (_currToken = JsonToken .FIELD_NAME );
384
392
}
385
- ScalarEvent scalar = (ScalarEvent ) evt ;
386
- String name = scalar .getValue ();
387
- _currentFieldName = name ;
388
- _parsingContext .setCurrentName (name );
389
- _currentAnchor = scalar .getAnchor ();
390
- return (_currToken = JsonToken .FIELD_NAME );
391
393
}
392
394
// Ugh. Why not expose id, to be able to Switch?
395
+ _currentAnchor = null ;
393
396
394
397
// scalar values are probably the commonest:
395
398
if (evt .is (Event .ID .Scalar )) {
0 commit comments