You are absolutely right, I wonder how I managed to write that on the first place. That method should return a 'null' JSONObject instead of JSONNull by doing the following
if( !(bean instanceof Person) ){
return new JSONObject(true); // marks the object as null
}
I'll update the info on the page as well, thanks for spotting it!
Cheers,
Andres
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Andres,
The example of a custom bean processor on your blog page doesn't compile:
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonBeanProcessor( Person.class,
new JsonBeanProcessor(){
public JSONObject processBean( Object bean, JsonConfig jsonConfig ){
if( !(bean instanceof Person) ){
return JSONNull.getInstance();
}
Person person = (Person) bean;
return new JSONObject()
.element( "name", person.getName() )
.element( "lastname", person.getLastname() );
}
});
I get a type mismatch, cannot convert from JSONNull to JSONObject. What should it return in this example?
Hi Andrew,
You are absolutely right, I wonder how I managed to write that on the first place. That method should return a 'null' JSONObject instead of JSONNull by doing the following
if( !(bean instanceof Person) ){
return new JSONObject(true); // marks the object as null
}
I'll update the info on the page as well, thanks for spotting it!
Cheers,
Andres