java - can't serialize class org.springframework.data.geo.Point -


i'm trying put aggregation query gps data using spring-data-mongodb 1.6.2. here's looks like:

    aggregation agg = newaggregation(             match(new criteria()                 .andoperator(                         criteria.where("eventtime").gte(filterdate),                          criteria.where("location").nearsphere(p).maxdistance(distance)                 )             ),             sort(direction.desc, "vanid", "eventtime"),             group("vanid").first(aggregation.root).as("first")     );      return mongotemplate.aggregate(agg,gpsdataentity.mongo_collection, groupedentity2.class);` 

the problem i'm seeing has due match() portion of query. exception long i've included stack point mongotemplate.aggregate() called in code snippet above:

caused by: java.lang.illegalargumentexception: can't serialize class org.springframework.data.geo.point @ org.bson.basicbsonencoder._putobjectfield(basicbsonencoder.java:284) @ org.bson.basicbsonencoder.putobject(basicbsonencoder.java:185) @ org.bson.basicbsonencoder._putobjectfield(basicbsonencoder.java:240) @ org.bson.basicbsonencoder.putobject(basicbsonencoder.java:185) @ org.bson.basicbsonencoder._putobjectfield(basicbsonencoder.java:240) @ org.bson.basicbsonencoder.putobject(basicbsonencoder.java:199) @ org.bson.basicbsonencoder._putobjectfield(basicbsonencoder.java:240) @ org.bson.basicbsonencoder.putobject(basicbsonencoder.java:185) @ org.bson.basicbsonencoder._putobjectfield(basicbsonencoder.java:240) @ org.bson.basicbsonencoder.putobject(basicbsonencoder.java:185) @ org.bson.basicbsonencoder._putobjectfield(basicbsonencoder.java:240) @ org.bson.basicbsonencoder.putiterable(basicbsonencoder.java:309) @ org.bson.basicbsonencoder._putobjectfield(basicbsonencoder.java:248) @ org.bson.basicbsonencoder.putobject(basicbsonencoder.java:185) @ org.bson.basicbsonencoder.putobject(basicbsonencoder.java:131) @ com.mongodb.defaultdbencoder.writeobject(defaultdbencoder.java:33) @ com.mongodb.outmessage.putobject(outmessage.java:289) @ com.mongodb.outmessage.writequery(outmessage.java:211) @ com.mongodb.outmessage.query(outmessage.java:86) @ com.mongodb.dbcollectionimpl.find(dbcollectionimpl.java:81) @ com.mongodb.db.command(db.java:317) @ com.mongodb.db.command(db.java:296) @ com.mongodb.db.command(db.java:371) @ com.mongodb.db.command(db.java:243) @ org.springframework.data.mongodb.core.mongotemplate$1.doindb(mongotemplate.java:326) @ org.springframework.data.mongodb.core.mongotemplate$1.doindb(mongotemplate.java:324) @ org.springframework.data.mongodb.core.mongotemplate.execute(mongotemplate.java:394) @ org.springframework.data.mongodb.core.mongotemplate.executecommand(mongotemplate.java:324) @ org.springframework.data.mongodb.core.mongotemplate.aggregate(mongotemplate.java:1418) @ org.springframework.data.mongodb.core.mongotemplate.aggregate(mongotemplate.java:1353)

the above query works fine if remove nearsphere criteria. i've verified point , distance being passed valid.

if can give pointers on i'm doing wrong i'd appreciate it.

this not bug in spring data mongodb.

actually turns out "$nearsphere" not allowed inside of $match aggregation expression. must use geonear(..) instead - see example below.

note mongodb requires geonear first element in aggreation pipeline.

@test public void serializepoinincriterianearsphere() throws exception {      mongotemplate.dropcollection(eventwithlocation.class);     mongotemplate.insert(new eventwithlocation(3, new point(-73.99408, 40.75057), "42"));      mongotemplate.indexops(eventwithlocation.class).ensureindex(new geospatialindex("location"));      point p = new point(-73, 40);     nearquery geonear = nearquery.near(p, metrics.kilometers).maxdistance(150.0);      typedaggregation<eventwithlocation> agg = newaggregation(eventwithlocation.class, //             geonear(geonear, "distance") //             , match(where("eventtime").gte(1)) //             , sort(direction.desc, "eventtime") //             , group("vanid").first(aggregation.root).as("first") //     );      aggregationresults<dbobject> results = mongotemplate.aggregate(agg, dbobject.class);     list<dbobject> list = results.getmappedresults();      dbobject firstresult = list.get(0);     assertthat(firstresult.get("_id"), is(equalto((object)"42"))); } 

you use critiera.within circle:

@test public void serializepoinincriterianearsphere() throws exception {  ... above ...      point p = new point(-73, 40);     circle circle = new circle(p, new distance(150.0, metrics.kilometers));      typedaggregation<eventwithlocation> agg = newaggregation(eventwithlocation.class, //             match(where("eventtime").gte(1).and("location").withinsphere(circle)) //             , sort(direction.desc, "eventtime") //             , group("vanid").first(aggregation.root).as("first") //     );  ... above } 

Popular posts from this blog

html/hta mutiple file in audio player -

debugging - Reference - What does this error mean in PHP? -