[JAVA-1761] DocumentCodec cannot serialize embedded Set Created: 14/Apr/15  Updated: 05/May/15  Resolved: 20/Apr/15

Status: Closed
Project: Java Driver
Component/s: Codecs
Affects Version/s: 3.0.0
Fix Version/s: 3.0.1, 3.1.0

Type: Improvement Priority: Minor - P4
Reporter: Jochen Kemnade Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

If an org.bson.Document contains a field whose value is a Set, serialization fails with

org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.util.Collections$UnmodifiableSet.
	at org.bson.codecs.configuration.CodecCache.getOrThrow(CodecCache.java:46)
	at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:63)
	at org.bson.codecs.configuration.ChildCodecRegistry.get(ChildCodecRegistry.java:51)
	at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:174)
	at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:189)
	at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:172)
...
	at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:131)
	at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:45)



 Comments   
Comment by Jeffrey Yemin [ 05/May/15 ]

Closed for 3.0.1 release.

Comment by Githook User [ 20/Apr/15 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: When encoding a Document, encode all Iterable instances as BSON arrays, rather than just List instances. This is consistent with the behavior of the DBObject encoder,
so this will make it easier to migrate from DBObject to Document

JAVA-1761
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/93be1cf5c18b6e88e4b41b783b77f94c49288c64

Comment by Githook User [ 20/Apr/15 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: When encoding a Document, encode all Iterable instances as BSON arrays, rather than just List instances. This is consistent with the behavior of the DBObject encoder,
so this will make it easier to migrate from DBObject to Document

JAVA-1761
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/fa60415971bd69a1e4cfbfc57fdfa1ca17ec329b

Comment by Jeffrey Yemin [ 14/Apr/15 ]

Thanks Jochen,

This is a reasonable request, though I'm going to remove the Regression label since Document is a new class. The DBObjectCodec does look for Iterable rather than List.

Comment by Jochen Kemnade [ 14/Apr/15 ]

In 2.x, that worked via com.mongodb.util.JSON.serialize(Object) and com.mongodb.util.JSONSerializers.IterableSerializer.serialize(Object, StringBuilder). Probably, org.bson.codecs.DocumentCodec.writeValue(BsonWriter, EncoderContext, Object) should check for Iterable instread of List.

Generated at Thu Feb 08 08:55:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.