Complex types in web services

S

ses

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??
 
P

projectmoon

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??

Most web app frameworks will have tools for serializing complex types in
web services. Spring has its own stuff, and there is a (proposed?)
standard called JAX-WS that will also do it. The main thing to watch out
for with complex types is cyclical references, assuming you're using
JSON. JSON cannot handle cyclical references.
 
A

Arne Vajhøj

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.

Arne
 
A

Arne Vajhøj

projectmoon said:
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??

Most web app frameworks will have tools for serializing complex types in
web services. Spring has its own stuff, and there is a (proposed?)
standard called JAX-WS that will also do it. The main thing to watch out
for with complex types is cyclical references, assuming you're using
JSON. JSON cannot handle cyclical references.

JAX-WS is out and has been for a *very* long time now. Much of it is
integrated with JDK 6 as of around update 11 or 14, I forget which. And
it can already handle some of these complex types. In particular, the
cited example of HashMap<String,String> can be done, since it uses only
known types inside. Doing one with a more complex type takes more work,
which is what JAXB is for.

JAX-WS came with 1.6.nothing.

And the default handling of HashMap is not that useful.

Arne
 
T

Tom Anderson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top