Return-Path: Delivered-To: apmail-cxf-users-archive@www.apache.org Received: (qmail 59510 invoked from network); 5 Jan 2009 18:53:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Jan 2009 18:53:48 -0000 Received: (qmail 97062 invoked by uid 500); 5 Jan 2009 18:53:41 -0000 Delivered-To: apmail-cxf-users-archive@cxf.apache.org Received: (qmail 97018 invoked by uid 500); 5 Jan 2009 18:53:41 -0000 Mailing-List: contact users-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@cxf.apache.org Delivered-To: mailing list users@cxf.apache.org Received: (qmail 97007 invoked by uid 99); 5 Jan 2009 18:53:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Jan 2009 10:53:41 -0800 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [64.79.199.57] (HELO server.dankulp.com) (64.79.199.57) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Jan 2009 18:53:31 +0000 Received: by server.dankulp.com (Postfix, from userid 5000) id 9774E2430022; Mon, 5 Jan 2009 13:53:10 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.2.5-gr0 (2008-06-10) on server.dankulp.com X-Spam-Level: X-Msg-File: /tmp/mailfilter.a1B7nYobs1 Received: from mia-awong.americas.progress.com (c-24-91-141-225.hsd1.ma.comcast.net [24.91.141.225]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by server.dankulp.com (Postfix) with ESMTP id 2E05A2430021; Mon, 5 Jan 2009 13:53:09 -0500 (EST) From: Daniel Kulp To: users@cxf.apache.org Subject: Re: HashMap with XmlJavaTypeAdapter key/value Date: Mon, 5 Jan 2009 13:53:16 -0500 User-Agent: KMail/1.9.9 Cc: Vasco Asturiano References: <494BC183.4020803@ripe.net> In-Reply-To: <494BC183.4020803@ripe.net> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200901051353.16770.dkulp@apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Status: No, score=-0.6 required=3.0 tests=AWL,BAYES_00,RCVD_IN_PBL, RCVD_IN_SORBS_DUL,RDNS_DYNAMIC autolearn=no version=3.2.5-gr0 I think the only solution is a specific adapter for each mapping. Definitely less than ideal. The best place to ask for advice would be on the jaxb lists: https://jaxb.dev.java.net/servlets/ProjectMailingListList Dan On Friday 19 December 2008 10:45:07 am Vasco Asturiano wrote: > Hello all, > > I am trying to render the following attribute: > > HashMap myField; > > SomeClass is not my class and is not xml annotated, therefore I created > a type adapter for it, which is included in the package-info.java: > > @XmlJavaTypeAdapter(value=SomeClassAdapter.class,type=SomeClass.class) > > The adapter contains something like: > > public class SomeClassAdapter extends XmlAdapter { > @Override > public String marshal(SomeClass c){ > return c.toString(); > } > > @Override > public SomeClass unmarshal(String s) { > return new SomeClass(s); > } > } > > This solution works fine when rendering direct attributes, as well as > lists and arrays: > > SomeClass c; > SomeClass[] arr; > List lst; > > But fails when rendering HashMap. The type adapter is not called when > the class is either the key or the value of a HashMap, and therefore the > attribute myField is rendered empty in the resulting XML. > > After researching for existing solutions I have tried is to create a > generic parametrizable adapter for the HashMap: > > public class HashMapAdapter extends > XmlAdapter , HashMap> > > This is the MapEntry class: > > @XmlAccessorType(XmlAccessType.FIELD) > public class MapEntry { > private K key; > private V value; > > private MapEntry(K key, V value) { > this.key = key; > this.value = value; > } > > public K getKey() { > return key; > } > > public V getValue() { > return value; > } > } > > However, this solution also doesn't work. Apparently, the key attribute > in the above class would only call the appropriate type adapter if it is > defined statically of being of that type, that is: > > private SomeClass key; > > Unfortunately, we have many combinations of different classes with > adapters which can be either key, or value, or both. Therefore declaring > the type statically would force us to declare an HashMap adapter for > each of the possible combinations. > > Did somebody else also came across the same problem and was able to find > work around it? > > Thanks plenty, -- Daniel Kulp dkulp@apache.org http://dankulp.com/blog