I'm working with netbeans and tried to use the json lib.
Unfortunately I got the following exception:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: net/sf/ezmorph/MorpherRegistry
at net.sf.json.util.JSONUtils.<clinit>(JSONUtils.java:59)
at net.sf.json.JSONArray.<init>(JSONArray.java:722)
at net.sf.json.JSONArray.fromJSONTokener(JSONArray.java:524)
at net.sf.json.JSONArray.fromString(JSONArray.java:375)
at net.sf.json.JSONArray.fromObject(JSONArray.java:293)
at net.sf.json.JSONArray.fromObject(JSONArray.java:253)
I tried a lot, googled around and have no idea.
Any idea ???
Jens
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You're missing (at least) one dependency, EZMorph. If you're not using maven to update
the dependencies, you've to manually download them. Please review the dependency list
at http://json-lib.sourceforge.net/dependencies.html to see which jars do you need.
-- Andres
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You have two options:
1) postprocess myAAA by applying a BeanMorpher to the result property that will transform the DynaBean into a LoginResponse
2) create a classMap and pass it as a third parameter to JSONObjetc.toBean() (<- better way)
Map classMap = new HashMap();
classMap.put( "result", LoginResponse.class );
Response myAAA = (Response) JSONObject.toBean( myNewObject, Response.class, classMap );
LoginResponse myWWW = (LoginResponse) myAAA.getResult(); // <- this should work now
Be carefult that this will convert every property named "result" on the bean hierarchy, meaning that if
LoginResponse has another property named "result" that is also an Object, it will be converted to LoginResponse.
Normally this shouldn't be a problem.
Cheers,
Andres
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm working with netbeans and tried to use the json lib.
Unfortunately I got the following exception:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: net/sf/ezmorph/MorpherRegistry
at net.sf.json.util.JSONUtils.<clinit>(JSONUtils.java:59)
at net.sf.json.JSONArray.<init>(JSONArray.java:722)
at net.sf.json.JSONArray.fromJSONTokener(JSONArray.java:524)
at net.sf.json.JSONArray.fromString(JSONArray.java:375)
at net.sf.json.JSONArray.fromObject(JSONArray.java:293)
at net.sf.json.JSONArray.fromObject(JSONArray.java:253)
I tried a lot, googled around and have no idea.
Any idea ???
Jens
Hi jbmb,
You're missing (at least) one dependency, EZMorph. If you're not using maven to update
the dependencies, you've to manually download them. Please review the dependency list
at http://json-lib.sourceforge.net/dependencies.html to see which jars do you need.
-- Andres
Thanks a lot.
Now I have another Problem.
I would like to use the json-rpc format.
Here is my actual class:
public class Response implements BaseResponse {
public String id;
public String error;
public Object result;
setter and getter
}
The problem is, that's not possible (for me) to use a generic Object for the result attribute.
JSONObject myNewObject = JSONObject.fromString( response );
Response myAAA = (Response) JSONObject.toBean(myNewObject, Response.class );
LoginResponse myWWW = (LoginResponse) myAAA.getResult();
That ends in:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: net.sf.ezmorph.bean.MorphDynaBean cannot be cast to LoginResponse
Using:
public LoginResponse result;
it works very well.
Any idea how to solve my problem ?
You have two options:
1) postprocess myAAA by applying a BeanMorpher to the result property that will transform the DynaBean into a LoginResponse
2) create a classMap and pass it as a third parameter to JSONObjetc.toBean() (<- better way)
Map classMap = new HashMap();
classMap.put( "result", LoginResponse.class );
Response myAAA = (Response) JSONObject.toBean( myNewObject, Response.class, classMap );
LoginResponse myWWW = (LoginResponse) myAAA.getResult(); // <- this should work now
Be carefult that this will convert every property named "result" on the bean hierarchy, meaning that if
LoginResponse has another property named "result" that is also an Object, it will be converted to LoginResponse.
Normally this shouldn't be a problem.
Cheers,
Andres