Complex types in web services

Discussion in 'Java' started by ses, Oct 22, 2010.

  1. ses

    ses Guest

    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??
     
    ses, Oct 22, 2010
    #1
    1. Advertising

  2. ses

    projectmoon Guest

    On Fri, 22 Oct 2010 02:54:29 -0700, 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??


    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.
     
    projectmoon, Oct 22, 2010
    #2
    1. Advertising

  3. ses

    Arne Vajhøj Guest

    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.

    Arne
     
    Arne Vajhøj, Oct 22, 2010
    #3
  4. ses

    Arne Vajhøj Guest

    On 22-10-2010 09:49, Steve W. Jackson wrote:
    > In article<4cc18968$0$15424$c3e8da3$>,
    > projectmoon<> wrote:
    >
    >> On Fri, 22 Oct 2010 02:54:29 -0700, 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??

    >>
    >> 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
     
    Arne Vajhøj, Oct 22, 2010
    #4
  5. ses

    Tom Anderson Guest

    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
     
    Tom Anderson, Oct 23, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael
    Replies:
    0
    Views:
    545
    Michael
    Sep 16, 2003
  2. Soren Kuula
    Replies:
    2
    Views:
    577
    Henry S. Thompson
    Dec 1, 2005
  3. Spam Catcher
    Replies:
    4
    Views:
    487
    John Saunders [MVP]
    Jul 6, 2007
  4. carmelo
    Replies:
    21
    Views:
    4,681
    csaffi
    Jul 23, 2009
  5. John
    Replies:
    4
    Views:
    467
Loading...

Share This Page