XML-RPC

Serialization/deserialization of Map does not retain correct datatype

Created: 21/Nov/06 07:12 PM   Updated: 28/Nov/08 08:53 PM
Return to search
Component/s: Source
Affects Version/s: 3.1
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments:
  Size
Zip Archive Licensed for inclusion in ASF works test.zip 2006-11-21 09:07 PM Jimisola Laursen 8 kB

Resolution Date: 24/Nov/06 08:33 PM


 Description  « Hide
Believe that this is quite severe bug unless I did something very wrong.
When sending/rretrieving a Map over XMLRPC the datatype is not correct. I've only checked for the keys, but the error might exist for the values as well.

Provided is a simple unit test to illustrate the bug. To reproduce run the unit tests in SerializationTest.
It has two test methods:
 
 1) one that calls a static method and
 2) and another that calls a method over XMLRPC which in turns call the same static method

The latter fails with a ClassCastException. Instead of the key being the expected Integer it is a String.


>From Console:
[...]
key: 21
value: twentyone
21 -> 'twentyone'
key: 1
value: one
1 -> 'one'
[...]
key: 21

>From Debug -> Variables (in Eclipse):

entry HashMap$Entry<K,V> (id=13)
key "21"
count 2
hash 1599
offset 0
value char[2] (id=27)
value "twentyone"
count 9
hash 0
offset 0
value char[9] (id=29)

As you can see 21 is a char[2] and not an integer as expected.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Jochen Wiedmann added a comment - 21/Nov/06 08:54 PM
Is there any attachment missing? What is "SerializationTest"?

Jimisola Laursen added a comment - 21/Nov/06 09:07 PM
Contains unit test to reveal possible bug.

Jimisola Laursen made changes - 21/Nov/06 09:07 PM
Field Original Value New Value
Attachment test.zip [ 12345443 ]
Jochen Wiedmann added a comment - 23/Nov/06 09:17 PM
When running your example, I receive the following error code:

    Failed to invoke method setMap in class xmlrpctest.TestRPCImpl:
    java.lang.String cannot be cast to java.lang.Integer

I find this quite understandable, because map keys can only be string, at least according to the XML-RPC spec. In other words, parameters like Map<Integer,...> cannot work.

Jimisola Laursen added a comment - 23/Nov/06 09:23 PM
Jochen,

You should run the unit test (it calls the getMap method) as specified in the original description.
The TestRPCImpl was just my class for testing out the behaviour and I kept it for reference.

It might be that map keys can only be strings according to the XML-RPC spec, but when extensions are enabled I honestly expect any Map (no matter what datatype keys are) to be handled properly.

Jochen Wiedmann added a comment - 23/Nov/06 10:22 PM
Your wish is my command. :-) Added in the trunk. Please let me know, whether we may close the issue.

Jimisola Laursen added a comment - 24/Nov/06 04:07 PM
Thank you! Does the current snapshot include this fix?

Jochen Wiedmann added a comment - 24/Nov/06 08:33 PM
Yes, I have deployed a current snapshot.

Jochen Wiedmann made changes - 24/Nov/06 08:33 PM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Jimisola Laursen added a comment - 25/Nov/06 04:42 PM
It works. Thank you.

Jochen Wiedmann added a comment - 28/Nov/08 08:53 PM
Closing issues which have been released.

Jochen Wiedmann made changes - 28/Nov/08 08:53 PM
Status Resolved [ 5 ] Closed [ 6 ]