Menu

#122 Ignore transient fields doesn't work on hierarchical classes

open
nobody
None
5
2011-06-22
2011-06-22
No

When I invoke net.sf.json.JsonConfig.setIgnoreTransientFields(true) there is an exception occurred during serialization to Json

java.lang.NoSuchFieldException: integerValue
at java.lang.Class.getDeclaredField(Class.java:1854)
at net.sf.json.JSONObject.isTransientField(JSONObject.java:1344)
at net.sf.json.JSONObject.defaultBeanProcessing(JSONObject.java:720)
at net.sf.json.JSONObject._fromBean(JSONObject.java:699)
at net.sf.json.JSONObject.fromObject(JSONObject.java:172)

It happens, when a class has a parent class with fields/getters. I noticed that in the net.sf.json.JSONObject#isTransientField( String name, Class beanClass, JsonConfig jsonConfig) there is a line:

Field field = beanClass.getDeclaredField( name );

getDeclaredField return a field only from the current class it doesn't look at the parent classess

Discussion


Log in to post a comment.