[JAVA-1894] Can't find a codec for class [Ljava.lang.String; Created: 17/Jul/15  Updated: 11/Sep/19  Resolved: 24/Sep/15

Status: Closed
Project: Java Driver
Component/s: Codecs
Affects Version/s: 3.0.2
Fix Version/s: None

Type: Task Priority: Minor - P4
Reporter: Stanislav Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

ubuntu x64, java 8



 Description   

Following the aggregation example
http://docs.mongodb.org/getting-started/java/aggregation/
I have tried to make a similar operation on my set of documents.
The only difference is that I tried to use $in in the $match clause.
The same operation in the shell works
db.getCollection('test').aggregate([ {"$match": {"code":

{"$in":["1111", "2223344"]}

}}]);

using the driver it looks like this
String[] codes =

{"1112233", "2223344"}

;
AggregateIterable<Document> iterable = db.getCollection("test").aggregate(asList(
new Document("$match", new Document("code", new Document("$in", codes)))));

however it fails with
Exception in thread "main" org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class [Ljava.lang.String;.
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.writeMap(DocumentCodec.java:189)
at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:172)
at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:189)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:131)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:45)
at org.bson.BsonDocumentWrapper.getUnwrapped(BsonDocumentWrapper.java:189)
at org.bson.BsonDocumentWrapper.get(BsonDocumentWrapper.java:129)
at com.mongodb.AggregateIterableImpl.execute(AggregateIterableImpl.java:118)
at com.mongodb.AggregateIterableImpl.forEach(AggregateIterableImpl.java:107)
at AggregationTest.main(AggregationTest.java:27)



 Comments   
Comment by Jeffrey Yemin [ 17/Jul/15 ]

The Document class currently supports only List, not native Java array, so just replace with:

List<String> codes = Arrays.asList("1112233", "2223344");

Comment by Stanislav [ 17/Jul/15 ]

Well, looking in the source code I found a codec for the List.
If I switch from String[] to ArrayList<String> it works.
Do no know whether or not String[] is needed, so sorry for the noise if not.

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