Re: Complex types in web services
On Fri, 22 Oct 2010, Arne Vajh?j wrote:
On 22-10-2010 05:54, ses wrote:
What's the best approach for dealing with complex types (such as
HashMap<String,String>) with web services? Obviously for full
interoperability the only option would be to convert to a string array
- String[][]
But I tried using a wrapper class around a HashMap<String, String> and
it will build and deploy fine, though when I query the web service
using a tool such as soapUI, I simply get<return/> as the value for
what should contain my hashmap wrapper.
Is there any way I can get the wsgen tool to generate a complex type
of this sort or is it a much better idea to use primitives??
I would convert HashMap<String,String> to NameValuePair[] - that
is a very portable structure.
That's a better idea than either a String[][] or a tool-mapped HashMap.
But i'd go a step further and use something with domain meaning instead
ofa a NameValuePair. Say, if you want to move the names of characters in a
play with their descriptions, send a List<CharacterDefinition>, where:
public class CharacterDefinition {
private final String name;
private final String description;
// constructor, getters, etc
}
That should get mapped into a suitable schema type, and leads to more
readable XML, and a measure of additional type safety and
self-documentation in the consuming system.
tom
--
I'm having trouble getting women. Does anyone have Justina Robson's
email? -- Martin