[JAVA-2050] Error: Can't find a codec for class com.mongodb.client.model.geojson.Polygon Created: 02/Dec/15  Updated: 11/Sep/19  Resolved: 14/Dec/15

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 3.1.1
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: riju pahwa Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mac-os ElCapital



 Description   

  
               Polygon polygon = new Polygon(Arrays.asList(new Position(boundingBox.getRightLongitude(),boundingBox.getTopLatitude()), 
                new Position(boundingBox.getLeftLongitude(), boundingBox.getTopLatitude()), 
                new Position(boundingBox.getLeftLongitude(), boundingBox.getBottomLatitude()), 
                new Position(boundingBox.getRightLongitude(), boundingBox.getBottomLatitude()),
                new Position(boundingBox.getRightLongitude(), boundingBox.getTopLatitude())));
		//Document filter = new Document("coordinates",geoWithin("coordinates", polygon));
		
		
		Block<Document> printBlock = new Block<Document>() {
		     @Override
		     public void apply(final Document document) {
		         System.out.println(document.toJson());
		     }
		};
		database.getCollection("restaurants").find(geoWithin("coordinates",polygon)).forEach(printBlock);



 Comments   
Comment by riju pahwa [ 04/Dec/15 ]

Thanks Jeff. I am not modifying the codec registry. I don't think I am loading the wrong class file. I did switch from 3.0.4 to 3.1.1.

I did switch my code to use morphia and that seemed to be working fine. Thanks again!

Comment by Jeffrey Yemin [ 03/Dec/15 ]

I'm not able to reproduce this with 3.1.1. There are a couple of possibilities to consider:

  1. Are you modifying the CodecRegistry via MongoClientOptions.Builder? If so, you may be missing the GeoJsonCodecProvider that is included by default in the codec registry.
  2. Are you loading the MongoClient class from the wrong jar file? To check this, you can run with verbose class loading on
Comment by riju pahwa [ 02/Dec/15 ]

Jeff - Thanks for the reply. I am seeing this with the above code not the commented one.

----Complete Stack Trace--

Dec 02, 2015 2:35:28 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Cluster created with settings

{hosts=[52.33.125.90:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}

Exception in thread "main" org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.mongodb.client.model.geojson.Polygon.
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.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37)
at com.mongodb.client.model.BuildersHelper.encodeValue(BuildersHelper.java:35)
at com.mongodb.client.model.Filters$GeometryOperatorFilter.toBsonDocument(Filters.java:997)
at com.mongodb.FindIterableImpl.createQueryOperation(FindIterableImpl.java:164)
at com.mongodb.FindIterableImpl.execute(FindIterableImpl.java:159)
at com.mongodb.FindIterableImpl.forEach(FindIterableImpl.java:150)
at co.nodal.connect.DAO.mongo.PlainAnalyticsDAO.getAllRoadNodesForBoundingBoxFromDatabase(PlainAnalyticsDAO.java:45)
at co.nodal.connect.DAO.mongo.PlainAnalyticsDAO.main(PlainAnalyticsDAO.java:81)

Comment by Jeffrey Yemin [ 02/Dec/15 ]

Are you seeing that with the pasted code, or with code that uses the commented out 'filter' variable? Can you provide a full stack trace please?

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