Am getting [sf.json.JSONObject] [% Property '<property>' has no read method. SKIPPED %] log messages only for Boolean properties when
am trying to create a JSONObject using
JSON json = JSONObject.fromBean(bean);
No doubt, it does work for boolean properties but am wondering why it doesn't work with Booleans.
My bean has some Boolean values with set<property>/is<property> methods.
For some reason we are not able to use set<property>/get<property> methods for Booleans in the bean.
Any help is greatly appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
does not follow the JavaBeans conventions, is<property> will only work for primitive booleans not wrappers as you have noticed. Json-lib expects your data to follow the JavaBeans convention, processing each bean with a PropertyInspector (from the java.beans package).
If possible please change your beans to either return a boolean primitive or prefer the get prefix instead of is. If you are unable to alter the code there may be an alternative (though it will require a bit of config), you may create a JsonBeanProcessor for each target bean you are interested in serializing and register them with JsonConfig, be sure to serialize your beans with that config, like so
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonBeanProcessor( Bean.class, new CustomJsonBeanProcessor() );
JSON json = JSONObject.fromObject( bean, jsonConfig );
// or even
// JSON json = JSONSerializer.toJSON( bean, jsonConfig );
Cheers,
Andres
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Am getting [sf.json.JSONObject] [% Property '<property>' has no read method. SKIPPED %] log messages only for Boolean properties when
am trying to create a JSONObject using
JSON json = JSONObject.fromBean(bean);
No doubt, it does work for boolean properties but am wondering why it doesn't work with Booleans.
My bean has some Boolean values with set<property>/is<property> methods.
For some reason we are not able to use set<property>/get<property> methods for Booleans in the bean.
Any help is greatly appreciated.
The problem is that a method with the signature
public Boolean isEnabled()
does not follow the JavaBeans conventions, is<property> will only work for primitive booleans not wrappers as you have noticed. Json-lib expects your data to follow the JavaBeans convention, processing each bean with a PropertyInspector (from the java.beans package).
If possible please change your beans to either return a boolean primitive or prefer the get prefix instead of is. If you are unable to alter the code there may be an alternative (though it will require a bit of config), you may create a JsonBeanProcessor for each target bean you are interested in serializing and register them with JsonConfig, be sure to serialize your beans with that config, like so
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonBeanProcessor( Bean.class, new CustomJsonBeanProcessor() );
JSON json = JSONObject.fromObject( bean, jsonConfig );
// or even
// JSON json = JSONSerializer.toJSON( bean, jsonConfig );
Cheers,
Andres