use of org.bson.codecs.BsonArrayCodec in project camel by apache.
the class MongoDbBasicConverters method fromStringToList.
@Converter
public static List<Bson> fromStringToList(String value) {
final CodecRegistry codecRegistry = CodecRegistries.fromProviders(Arrays.asList(new ValueCodecProvider(), new BsonValueCodecProvider(), new DocumentCodecProvider()));
JsonReader reader = new JsonReader(value);
BsonArrayCodec arrayReader = new BsonArrayCodec(codecRegistry);
BsonArray docArray = arrayReader.decode(reader, DecoderContext.builder().build());
List<Bson> answer = new ArrayList<>(docArray.size());
for (BsonValue doc : docArray) {
answer.add(doc.asDocument());
}
return answer;
}
Aggregations