Skip to content

Commit e137272

Browse files
committed
add possibility to read root-level Maps (theoretical as avro codec doesn't seem to support)
1 parent 156d20f commit e137272

File tree

1 file changed

+16
-6
lines changed
  • avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser

1 file changed

+16
-6
lines changed

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser/MapReader.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,36 @@ public JsonToken nextToken() throws IOException
6060
_parser.setAvroContext(this);
6161
_count = _decoder.readArrayStart();
6262
_state = (_count > 0) ? STATE_NAME : STATE_END;
63-
return JsonToken.START_OBJECT;
63+
return (_currToken = JsonToken.START_OBJECT);
6464
case STATE_NAME:
6565
if (_index < _count) {
6666
_state = STATE_VALUE;
6767
_currentName = _decoder.readString();
68-
return JsonToken.FIELD_NAME;
68+
return (_currToken = JsonToken.FIELD_NAME);
6969
}
7070
// need more data...
7171
_count = _decoder.arrayNext();
7272
// more stuff?
7373
if (_count > 0L) {
7474
_index = 0;
7575
_currentName = _decoder.readString();
76-
return JsonToken.FIELD_NAME;
76+
return (_currToken = JsonToken.FIELD_NAME);
7777
}
7878
// otherwise fall through:
7979
case STATE_END:
80+
final AvroReadContext parent = getParent();
81+
// as per [dataformats-binary#38], may need to reset, instead of bailing out
82+
// ... note, however, that we can't as of yet test it, alas.
83+
if (parent.inRoot()) {
84+
if (!_decoder.isEnd()) {
85+
_index = 0;
86+
_state = STATE_START;
87+
return (_currToken = JsonToken.END_OBJECT);
88+
}
89+
}
8090
_state = STATE_DONE;
81-
_parser.setAvroContext(getParent());
82-
return JsonToken.END_OBJECT;
91+
_parser.setAvroContext(parent);
92+
return (_currToken = JsonToken.END_OBJECT);
8393
case STATE_VALUE:
8494
break;
8595
case STATE_DONE:
@@ -93,7 +103,7 @@ public JsonToken nextToken() throws IOException
93103
}
94104
AvroStructureReader r = _structureReader.newReader(this, _parser, _decoder);
95105
_parser.setAvroContext(r);
96-
return r.nextToken();
106+
return (_currToken = r.nextToken());
97107
}
98108

99109
@Override

0 commit comments

Comments
 (0)