I use json-lib2.2 run the following code is right;
but when use json-lib2.4 is wrong.
I find method _fromJSONObject of JSONObject class has a bug,
at line 919 code jsonObject.setInternal( key, value, jsonConfig );
should be jsonObject._setInternal( key, value, jsonConfig );
code:
public class Tb {
private String columns;
private String portalLayout;
public String getColumns() {
return columns;
}
public void setColumns(String columns) {
this.columns = columns;
}
public String getPortalLayout() {
return portalLayout;
}
public void setPortalLayout(String portalLayout) {
this.portalLayout = portalLayout;
}
public static void main(String[] args) {
Tb t = new Tb();
t.setColumns("2");
t.setPortalLayout("[{\"id\":\"UserOrgs\"}]");
JSONObject obj = JSONObject.fromObject(t);
String json = obj.toString();
System.out.println(json);
JSONObject obj2= JSONObject.fromObject(json);
Tb t2 = (Tb)JSONObject.toBean(obj2, Tb.class);
System.out.println(t2.getPortalLayout());
}
}
Development of this library has been moved to GitHub since 2010, please report any issues you may find at https://github.com/kordamp/json-lib/issues