[newbie] Unable to decode array parameter from JSON request on jsonwebservice-ri-0.6.0.jar

126 views
Skip to first unread message

param

unread,
Aug 4, 2011, 11:37:42 AM8/4/11
to jsonwebservice
Hi,

I recently downloaded and started using jsonwebservice and got the
hello world war up and running. Everything works fine until I try to
submit an array as an argument in the json request. I am using ruby as
the client side code. My request is of the format:
{"methodname":{"arg1":12.96,"arg2":77.56,"arg3":[1,2,3]}}

My webservice method is set up as:
@WebMethod(operationName = "methodname")
public @WebResult(name = "message") ArrayList<object> methodname(
@WebParam(name = "arg1") double arg1,
@WebParam(name = "arg2") double arg2,
@WebParam(name = "arg3") int[] arg3)

On the server side, I am getting an exception as follows:
SEVERE: Couldn't create SOAP message due to exception:
com.jaxws.json.codec.JSONFault: Failed to create message
body.java.util.ArrayList cannot be cast to java.util.Map
com.sun.xml.ws.protocol.soap.MessageCreationException: Couldn't create
SOAP message due to exception: com.jaxws.json.codec.JSONFault: Failed
to create message body.java.util.ArrayList cannot be cast to
java.util.Map
at
com.jaxws.json.codec.JSONCodec.throwMessageCreationException(JSONCodec.java:
544)
at com.jaxws.json.codec.JSONCodec.decode(JSONCodec.java:503)
at
com.sun.xml.ws.transport.http.HttpAdapter.decodePacket(HttpAdapter.java:
321)
Caused by: com.jaxws.json.codec.JSONFault: Failed to create message
body.java.util.ArrayList cannot be cast to java.util.Map
at
com.jaxws.json.codec.decode.JSONDecoder.getWSMessage(JSONDecoder.java:
198)
at com.jaxws.json.codec.JSONCodec.decode(JSONCodec.java:497)
... 26 more
Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be
cast to java.util.Map
at
com.jaxws.json.codec.MessageBodyBuilder.handleMessage(MessageBodyBuilder.java:
121)
at
com.jaxws.json.codec.decode.JSONDecoder.getWSMessage(JSONDecoder.java:
196)



----------
I also tried using ArrayList/Array instead of int[] but that gave the
same exception as above. Taking arg3 out of the scenario makes it
work. I also tried converting the array into a map, but that gave a
different exception. Next,
I tried downloading the source for MessageBodyBuilder.java and
including it into my webapp so that I could debug it, but I am facing
some issues over there as well.

jsonwebservice

unread,
Aug 4, 2011, 2:38:12 PM8/4/11
to jsonwebservice
Hi,
jsonwebservice tested with rpc-literal encoding. Array or ArrayList
as first level parameter not supported in rpc-literal soap
specification. Only rpc document encoding do support array encoding.

If you are not sure about what is rpc-literal and rpc-document, simple
answer to your issue is don't use array or arraylist as first level
parameter. Wrap it with object.

like bellow,

public class ArrayWrap{
private ArrayList<Integer> myArray;
public ArrayList<Integer> getMyArray(){
return myArray;
}
public void setMyArray(ArrayList<Integer> array){
this.array = myArray;
}
}

then web method like follow

@WebMethod(operationName = "methodname")
public @WebResult(name = "message") ArrayList<object>
methodname(
@WebParam(name = "arg1") double arg1,
@WebParam(name = "arg2") double arg2,
@WebParam(name = "arg3") ArrayWrap arg3)


Or even more better look of move all parameter to one class and use it
as parameter, like bellow

class MyParameter{
private double arg1;
private double arg2;
ptivate int[] arg3;
///Getter and setters

}


and web method like bellow
@WebMethod(operationName = "methodname")
public @WebResult(name = "message") ArrayList<object>
methodname(
@WebParam(name = "myargs") MyParameter myargs)
{
...
}


Regards
Sundar

param

unread,
Aug 4, 2011, 3:32:38 PM8/4/11
to jsonwebservice
Thanks, this worked perfectly.

regards
Reply all
Reply to author
Forward
0 new messages