import javax.annotation.Generated;
import com.google.gson.annotations.SerializedName;
@Generated("net.hexar.json2pojo")
@SuppressWarnings("unused")
public class Asteroids {
@SerializedName("near_earth_objects")
private NearEarthObjects mNearEarthObjects;
public NearEarthObjects getNearEarthObjects() {
return mNearEarthObjects;
}
public void setNearEarthObjects(NearEarthObjects nearEarthObjects) {
mNearEarthObjects = nearEarthObjects;
}
}
// And a lot of subclasses
What you expected:
I have class names like "_2019-09-05" and I want to assign numeric json components to those classes.
What you did:
ObjectMapper objectMapper = new ObjectMapper();
// objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
if (response.isSuccessful()) {
try {
ex = objectMapper.readValue(data.toString(), Asteroids.class);
} catch (JsonMappingException e) {
e.printStackTrace();
}
}
System.out.println(ex.toString());
What you got:
at [Source: (StringReader); line: 1, column: 16] (through reference chain: com.nurettinabaci.Asteroids["2019-09-05"])
at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:840)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1179)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1592)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1570)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:294)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4202)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3205)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3173)
at com.nurettinabaci.Main.main(Main.java:41)
Exception in thread "main" java.lang.NullPointerException
at com.nurettinabaci.Main.main(Main.java:46)
Your JSON dictionary:
Your model:
What you expected:
I have class names like "_2019-09-05" and I want to assign numeric json components to those classes.
What you did:
What you got: