Assuming you have a structure like the following within mongo db and try to decode it manually, not using org.bson.codecs.DocumentCodec a NullPointerException is being thrown if you trty to decode a nested ARRAY structure.
database-object:
{ "_id" : ObjectId("585d002202ef6c0c985cd350"), "listOfList" : [ [ ] ] }Stacktrace:
java.lang.NullPointerException at org.bson.codecs.IterableCodec.readValue(IterableCodec.java:118) at org.bson.codecs.IterableCodec.decode(IterableCodec.java:78) at org.bson.codecs.IterableCodec.decode(IterableCodec.java:37)
SampleCode to replay:
Codec<List> listCodec = mongoClient.getMongoClientOptions().getCodecRegistry().get(List.class); List decode = listCodec.decode(new JsonReader("[ [ ] ]"), DecoderContext.builder().build());
Remark:
If using the org.bson.codecs.DocumentCodec array structures are handled by org.bson.codecs.DocumentCodec itself, so there the problem does not exist.
I am not 100% sure tht IterableCodec should be able to handle Arrays, I just saw the comments in org.bson.codecs.BsonTypeClassMap stating that ARRAYS are supported. Unfortunately there is no mapping in th defaults section.