I am mapping a json string to a class using jsonson mapper. The class is as follows:
class MyClass{
@JsonProperty("my_boolean")
private boolean myBoolean;
@JsonProperty("my_int")
private int myInt;
}
I want to check if the myBoolean and myInt fields are set or contain default values (false and 0). I tried using reflection and checking if the field was null, but I think this will not work for primitive types. This is what I have now:
Field[] fields = myClass.getClass().getDeclaredFields();
for (Field field : fields) {
try {
field.setAccessible(true);
Object myObject = field.get(myClass);
if(myObject != null) {
}
}
}
How else can I check this?
Thanks.
source
share