Menu

#117 Non-string public fields fail

open
nobody
None
5
2011-02-18
2011-02-18
No

I tried to enable ignorePublicFields introduced in issue 2513691 but it failed when deserializing json to a bean. I narrowed it down to the attached test case. The test bean has one String property and one int property and fails on the int property with:

Exception in thread "main" net.sf.json.JSONException: java.lang.NoSuchMethodException: Unknown property 'id' on class 'class PublicFieldsTestBean'
at net.sf.json.util.PropertySetStrategy$DefaultPropertySetStrategy._setProperty(PropertySetStrategy.java:69)
at net.sf.json.util.PropertySetStrategy$DefaultPropertySetStrategy.setProperty(PropertySetStrategy.java:57)
at net.sf.json.JSONObject.setProperty(JSONObject.java:1394)
at net.sf.json.JSONObject.toBean(JSONObject.java:429)
at PublicFieldsTest.main(PublicFieldsTest.java:11)
Caused by: java.lang.NoSuchMethodException: Unknown property 'id' on class 'class PublicFieldsTestBean'
at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2123)
at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:890)
at net.sf.json.util.PropertySetStrategy$DefaultPropertySetStrategy._setProperty(PropertySetStrategy.java:67)
... 4 more

If I add a setter for the property, it works. If I change the property to String, it works.

Discussion

  • Anders Olsson

    Anders Olsson - 2011-02-18
     
  • Anders Olsson

    Anders Olsson - 2011-02-18
     

Log in to post a comment.