You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "L. J.W" <lj...@gmail.com> on 2009/06/17 08:25:26 UTC

Has cxf 2.2.2 support hashmap databinding?

Hi all,I am using cxf 2.2.2,in
sample/java_first_jaxws/HelloWorld.java,I found the comment:
  /* Map passing
     * JAXB also does not support Maps.  It handles Lists great, but Maps
are
     * not supported directly.  They also require use of a XmlAdapter to map
     * the maps into beans that JAXB can use.
     */
    @XmlJavaTypeAdapter(IntegerUserMapAdapter.class)
    Map<Integer, User> getUsers();

It seems map not supported by cxf or jaxb.

but I write my SEI like following:

public StudentInfo getStudentInfo(String studentId);

and StudentInfo.java like following:

.....

private Map  addressMap;

   public Map<String,Address> getAddressMap() {
        return addressMap;
    }
    public void setAddressMap(Map<String,Address> addressMap) {
        this.addressMap = addressMap;
    }

.....

then I publish above to web service.

and I find the map in StudentInfo can transfer from service provider to
service consumer.

so,I am confused whether cxf 2.2.2 support map databinding or not?

Thanks.

Re: Has cxf 2.2.2 support hashmap databinding?

Posted by Daniel Kulp <dk...@apache.org>.
It kind of depends on where the Map is used.   If it's used inside a JAXB 
bean, it will work fine.   When JAXB is processing the bean, it recognizes the 
map and will create a "generic" schema for it.  (not pretty, but works).    
The schema kind of sucks which is why the @XmlJavaTypeAdapter is strongly 
recommended.   

However, you cannot create a JAXB context that will marshall/unmarshall a Map.  
It will throw a "interfaces are not allowed" type of exception.   Thus, Maps 
aren't really usable for top level types.

Thus, it's a kind of "half supportable" type thing.

Dan


On Wed June 17 2009 2:25:26 am L. J.W wrote:
> Hi all,I am using cxf 2.2.2,in
> sample/java_first_jaxws/HelloWorld.java,I found the comment:
>   /* Map passing
>      * JAXB also does not support Maps.  It handles Lists great, but Maps
> are
>      * not supported directly.  They also require use of a XmlAdapter to
> map * the maps into beans that JAXB can use.
>      */
>     @XmlJavaTypeAdapter(IntegerUserMapAdapter.class)
>     Map<Integer, User> getUsers();
>
> It seems map not supported by cxf or jaxb.
>
> but I write my SEI like following:
>
> public StudentInfo getStudentInfo(String studentId);
>
> and StudentInfo.java like following:
>
> .....
>
> private Map  addressMap;
>
>    public Map<String,Address> getAddressMap() {
>         return addressMap;
>     }
>     public void setAddressMap(Map<String,Address> addressMap) {
>         this.addressMap = addressMap;
>     }
>
> .....
>
> then I publish above to web service.
>
> and I find the map in StudentInfo can transfer from service provider to
> service consumer.
>
> so,I am confused whether cxf 2.2.2 support map databinding or not?
>
> Thanks.

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog