NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ
for more details.
I've noticed something curious while testing some web services recently. The keys and values in the HashMap object that's passed as an IN parameter to the web service were all being turned into nulls. If I passed one key/value pair, I'd get one key/value pair of nulls, if I passed two key/value pairs, I'd get a pair of null/null, and so on. I did eventually track down the problem and fixed it, but it has been an interesting issue to come across.
I created a test method that simply had one IN parameter that was the HashMap
. Inside the method, I logged the keys and values that were passed to me...
This was the kind of output being produced...
When I looked into the XSDs associated with the WSDL generated for the web service, I noticed something strange, the key
for its data type.
This made be look at my WebMethod
again. I realised that the HashMap
was defined as untyped. Once I changed the definition to specify <String,String> as the key/value types the whole thing started to behave as expected.
The output became...
The XSD also changed to...
is what's important here. Looks like JAX-WS cannot process HashMaps that are not typed. Once an explicit type is specified, everything works correctly.
So in a nutshell, if using a HashMap in your WebMethod
, be sure to type it correctly. In the end I changed my WebMethod
definition to this:
A quick disclaimer...
Although I put in a great effort into researching all the topics I cover, mistakes can happen.
If you spot something out of place, please do let me know.
All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle).
Use of any information contained in this blog post/article is subject to this disclaimer
Other posts you may like...