2

Getting this error on retrieving data from database (MongoDB driver V3.10.2, springboot V2.0, spring cloud V-Finchley.M9).

Recently we have upgraded the springboot version from 1.3 to 2.0 and mongodb driver to latest once. Before upgrading this code was working but now it suddenly stopped working.

Java Class POJO:

public class Positions {
        private String type ="Polygon";
        private List<List<List<Double>>> coordinates;

        public List<List<List<Double>>> getCoordinates() {
            return coordinates;
        }

        public void setCoordinates(List<List<List<Double>>> coordinates) {
            this.coordinates = coordinates;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }
    }

MongoDB data, which I am trying to map:

"positionsFrom" : {
        "type" : "Polygon",
        "coordinates" : [ 
            [ 
                [ 
                    13.9092758594177, 
                    44.8984249954859
                ], 
                [ 
                    13.921764224591, 
                    44.8985769926884
                ], 
                [ 
                    13.9218071399353, 
                    44.901373669501
                ], [ 
                    13.9092758594177, 
                    44.8984249954859
                ]
            ]
     ]
}

The error log:

org.springframework.data.mapping.MappingException: Cannot convert [14.245518205126928, 50.112434905459665] of type class java.util.ArrayList into an instance of class java.lang.Object! Implement a custom Converter<class java.util.ArrayList, class java.lang.Object> and register it with the CustomConversions. Parent object was: ClassPojo [direction = null, originCity = null, destinationCity = null, effectiveStartDate = 2019-04-11, effectiveEndDate = 2019-12-28, destination = null, currency = com.darwin.domain.model.Currency@490a218f, routeNumber = null, pickUp = null, _id = 5cb56d7db04d6442ad1ec487, adultRate = null, childRate = null, vehicleType = null, capacity = null] -> com.darwin.domain.localTransfers.LocalTransfer$Positions@77c9fddd
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readCollectionOrArray(MappingMongoConverter.java:980)
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readCollectionOrArray(MappingMongoConverter.java:985)
    at 
4
  • 1
    Any Stack trace ? And pom file Commented Aug 9, 2019 at 13:10
  • error log please Commented Aug 9, 2019 at 13:11
  • Provide the error log? Commented Aug 9, 2019 at 13:14
  • Hi.. i have added error logs in edited question Commented Aug 10, 2019 at 6:53

1 Answer 1

1

Use org.springframework.data.mongodb.core.convert Customconversions instead of Mongocustomcoversions. There is no need to write extra conversion but remember old Customconversions is deprecated. This is quick fix.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.