[JAVA-2056] Updates.set fails with List type Created: 08/Dec/15  Updated: 19/Oct/16  Resolved: 09/Apr/16

Status: Closed
Project: Java Driver
Component/s: Codecs
Affects Version/s: 3.1.0
Fix Version/s: 3.3.0

Type: Bug Priority: Major - P3
Reporter: Jochen Kemnade Assignee: Jeffrey Yemin
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 Description   

collection.findOneAndUpdate(Filters.eq('_id', id), Updates.set('a', list));

fails with

org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.util.Arrays$ArrayList.
	at org.bson.codecs.configuration.CodecCache.getOrThrow(CodecCache.java:46) ~[mongo-java-driver-3.1.0.jar:na]
	at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:63) ~[mongo-java-driver-3.1.0.jar:na]
	at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37) ~[mongo-java-driver-3.1.0.jar:na]
	at $CodecRegistry_2952b5e77739.get(Unknown Source) ~[na:na]
	at com.mongodb.client.model.BuildersHelper.encodeValue(BuildersHelper.java:35) ~[mongo-java-driver-3.1.0.jar:na]
	at com.mongodb.client.model.Updates$SimpleUpdate.toBsonDocument(Updates.java:442) ~[mongo-java-driver-3.1.0.jar:na]
	at com.mongodb.MongoCollectionImpl.toBsonDocument(MongoCollectionImpl.java:516) ~[mongo-java-driver-3.1.0.jar:na]
	at com.mongodb.MongoCollectionImpl.findOneAndUpdate(MongoCollectionImpl.java:380) ~[mongo-java-driver-3.1.0.jar:na]



 Comments   
Comment by Githook User [ 09/Apr/16 ]

Author:

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

Message: JAVA-2056: Add MongoClient support for encoding instances of Iterable, which is particularly handy when using Filters and Updates classes
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/d12a26efad19f876e53829c8a8444d5e5340c765

Comment by Sergey Polovko [ 11/Mar/16 ]

Have the same issue. Fixed it with copypasted Updates class and fixed version of BuildersHelper class.
See gist https://gist.github.com/jamel/892f871c35a8a2e3bda9 for more details.

Comment by Ross Lawley [ 14/Dec/15 ]

Another example seen on the MongoDB User group:

myCollection.updateOne(filter, set("myMapField", myMap));

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