CosmosDB coordinate data to Java model issue
HI,
I am trying to build a Spring Boot project with some RESTFul apis to retrieve document from Azure CosmosDB (via SQL API v3).
Here are the sample data:
vessel {
"mmsi": 368102360,
"location": {
"type": "Point",
"coordinates": [
-90.255,
38.5383333333
]
},
}
The mapped Java model:
@Data
public class Vessel {
@Id
private String id;
private String mmsi;
private Location location;
}
@Data
public class Location {
private String type;
private ArrayList <Coordinate> coordinates;
}
@Data
public class Coordinate {
Double latitude;
Double longitude;
}
I am hitting the error:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of .model.Coordinate
(although at least one Creator exists): no double/Double-argument constructor/factory method to deserialize from Number value (-90.255)
at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: .model.Vessel["location"]->.model.Location["coordinates"]->java.util.ArrayList[0])
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63) ~[jackson-databind-2.11.2.jar:2.11.2]
What would be the proper mapping for the dataset?
note it works for the following def:
private ArrayList coordinates;
But it would be nice to define a Coordinate object to better object traversal and interpretation.
Thanks!