I am getting the following exception while trying to fetch data from Mongo DB using a Java application.
String mongodbURL = env.getProperty("spring.data.mongodb.uri");
com.mongodb.client.MongoClient client = MongoClients.create( mongodbURL);
MongoDatabase mongoDatabase = client.getDatabase("EDD");
MongoCollection<org.bson.Document> coll = mongoDatabase.getCollection("ZipStoreDistanceData");
MongoCollection<StoreListForZip> zipCodeMongoCollection = mongoDatabase.getCollection("ZipStoreDistanceData",
StoreListForZip.class);
Bson filter = and(eq("_id", zipcode), lte("storeList.distanceInMiles", distance));
StoreListForZip storeListForZip = zipCodeMongoCollection.find(filter).first();
The line StoreListForZip storeListForZip = zipCodeMongoCollection.find(filter).first();
is the one which throws exception.
The exception is below
Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.blah.blah.dto.StoreListForZip```
my document looks like below in Mongo DB
{"_id":"US_00721","countryCode":"US","countryZip":"US_00721","storeList":[{"distanceInMiles":{"$numberInt":"20"},"storeNum":"11010"},{"distanceInMiles":{"$numberInt":"20"},"storeNum":"21111"},{"distanceInMiles":{"$numberInt":"17"},"storeNum":"31176"},{"distanceInMiles":{"$numberInt":"20"},"storeNum":"33060"},{"distanceInMiles":{"$numberInt":"17"},"storeNum":"51176"},{"distanceInMiles":{"$numberInt":"20"},"storeNum":"53060"}]}```
any insight into why the Java application is throwing this exception ?
my POJO class looks like below.
@Data
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class StoreListForZip {
@JsonProperty("id")
@Id
String id;
@JsonProperty("countryZip")
String countryZip;
@JsonProperty(value = "countryCode")
String countryCode;
@JsonProperty(value = "storeList")
List<StoreDistance> storeList;
}```