Skip to content

Commit

Permalink
Try-with-resources for EnumMap object decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
oujesky committed Apr 12, 2024
1 parent 3eb4ecd commit 8cfd068
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ public Deserializer<EnumMap<E, V>> createSpecific(DecoderContext context, Argume
return (decoder, decoderContext, mapType) -> {
final EnumMap<E, V> map = new EnumMap<>(enumType.getType());
final RemainingLimits remainingLimits = decoderContext.getSerdeConfiguration().map(LimitingStream::limitsFromConfiguration).orElse(LimitingStream.DEFAULT_LIMITS);
final Decoder objectDecoder = decoder.decodeObject(mapType);
String key = objectDecoder.decodeKey();
while (key != null) {
JsonNodeDecoder keyDecoder = JsonNodeDecoder.create(JsonNode.createStringNode(key), remainingLimits);
E k = enumDeser.deserialize(keyDecoder, decoderContext, enumType);
if (valueDeser == null) {
map.put(k, (V) objectDecoder.decodeArbitrary());
} else {
map.put(k, valueDeser.deserializeNullable(objectDecoder, decoderContext, valueType));
try (final Decoder objectDecoder = decoder.decodeObject(mapType)) {
String key = objectDecoder.decodeKey();
while (key != null) {
JsonNodeDecoder keyDecoder = JsonNodeDecoder.create(JsonNode.createStringNode(key), remainingLimits);
E k = enumDeser.deserialize(keyDecoder, decoderContext, enumType);
if (valueDeser == null) {
map.put(k, (V) objectDecoder.decodeArbitrary());
} else {
map.put(k, valueDeser.deserializeNullable(objectDecoder, decoderContext, valueType));
}
key = objectDecoder.decodeKey();
}
key = objectDecoder.decodeKey();
}
objectDecoder.finishStructure();
return map;
};
}
Expand Down

0 comments on commit 8cfd068

Please sign in to comment.