I'm trying to implement the global magnet API in an android application. I do a rest API get request and put the json API data in a string
(this string is called dataString
. This string looks like this:
{
declination: {
units: "Deg",
value: -4.8235602378845215
},
inclination: {
units: "Deg",
value: -30.085556030273438
},
total_intensity: {
units: "nT",
value: 31945.123046875
}
}
I'm now trying to deserialize this string into an object. I've made the following classes:
public class MagneticData {
@JsonProperty("declination")
public MagneticDataElement declination;
@JsonProperty("grid_variation")
public MagneticDataElement grid_variation;
@JsonProperty("inclination")
public MagneticDataElement inclination;
@JsonProperty("total_intensity")
public MagneticDataElement total_intensity;
}
public class MagneticDataElement {
@JsonProperty("units")
public String units;
@JsonProperty("value")
public double value;
}
I now use the ObjectMapper.readValue()
function to convert the dataString
to an object of the type MagneticData
but i get the following error:
com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.mobcom.apitest.MainActivity$MagneticData: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
What am i doing wrong?