You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by cwilkes <cw...@ladro.com> on 2008/03/13 22:10:11 UTC

@XmlJavaTypeAdapter with HashMap creates two fields on SOAP object

One of my WebParams has a HashMap in it and so I've annotated the field with
@XmlJavaTypeAdapter and created an XmlAdapter for it.  The java generated
from the WSDL has a field that's listed in that Adapter along with a
"HashMap" that extends "AbstractMap", both in my namespace.

The "HashMap" object has getters and setters based on the fieldName while
the holder object for a List of my Entries is based on the method name. 
That is this class:

@XmlRootElement
public class AdRequest {
  @XmlJavaTypeAdapter(QueryParametersAdapter.class)
  private Map<String, String[]> m_queryParameters;
  public Map<String, String[]> getQueryParameters() { ... }
  public void setQueryParameters(Map<String, String[]> p_queryParameters) {}
}

Turns into this after wsdl2java:

public class AdRequest  implements java.io.Serializable {
    private mynamespace.HashMap m_queryParameters;
    private mynamespace.AdRequestQueryParametersEntry[] queryParameters;
}

Where mynamespace.HashMap extends mynamespace.AbstractMap.

Marshalling and unmarshalling works fine with my Map<String,String[]> values
added via setQueryParameters(AdRequestQueryParametersEntry[]).  I'm just
annoyed that this HashMap shows up.

I've tried to annotate with XmlAccessType set to PUBLIC_MEMBER (the default)
and PROPERTY but it hasn't helped me out.

If I change the field name in my original AdRequest to "queryParameters" I
get this error in my logs:

Class has two properties of the same name "queryParameters"
	this problem is related to the following location:
		at public java.util.Map com.ladro.cxf.image.AdRequest.getQueryParameters()
		at com.ladro.cxf.image.AdRequest
	this problem is related to the following location:
		at private java.util.Map com.ladro.cxf.image.AdRequest.queryParameters
		at com.ladro.cxf.image.AdRequest

which does make sense.

Has anyone else seen this?  I've also tried marking the field as
XmlTransient but then JAXB ignores the getters and setters.
-- 
View this message in context: http://www.nabble.com/%40XmlJavaTypeAdapter-with-HashMap-creates-two-fields-on-SOAP-object-tp16038742p16038742.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: @XmlJavaTypeAdapter with HashMap creates two fields on SOAP object

Posted by cwilkes <cw...@ladro.com>.
Arg, the problem I had was that my parameters for the XmlAdapter were
reversed.  I now have it as

  public class QueryParametersAdapter extends
XmlAdapter<QueryParametersList, HashMap<String, String[]>>

and everything works fine.  After I clean this up I'll follow up to this
message with a link to this very simple project.

Thanks for the quick response!

Chris




dkulp wrote:
> 
> 
> If you read the javadoc for the XmlAccessType class, (I just did, I 
> didn't realize this either), even private fields will be grabbed if they 
> have a JAXB annotation on them. 
> 
> Thus, you might want to change to:
> XmlAccessType.FIELD
> to only look at the field.
> 
> Alternatively, take the @XmlJavaTypeAdapter annotation off the field and 
> stick it on the getter.   Thus, the field won't have any jaxb 
> annotations on it.   JAXB SHOULD allow it to work that way.
> 
> Dan
> 
> 
> -- 
> J. Daniel Kulp
> Principal Engineer, IONA
> dkulp@apache.org
> http://www.dankulp.com/blog
> 
> 

-- 
View this message in context: http://www.nabble.com/%40XmlJavaTypeAdapter-with-HashMap-creates-two-fields-on-SOAP-object-tp16038742p16039193.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: @XmlJavaTypeAdapter with HashMap creates two fields on SOAP object

Posted by Daniel Kulp <dk...@apache.org>.
If you read the javadoc for the XmlAccessType class, (I just did, I 
didn't realize this either), even private fields will be grabbed if they 
have a JAXB annotation on them. 

Thus, you might want to change to:
XmlAccessType.FIELD
to only look at the field.

Alternatively, take the @XmlJavaTypeAdapter annotation off the field and 
stick it on the getter.   Thus, the field won't have any jaxb 
annotations on it.   JAXB SHOULD allow it to work that way.

Dan


On Thursday 13 March 2008, cwilkes wrote:
> One of my WebParams has a HashMap in it and so I've annotated the
> field with @XmlJavaTypeAdapter and created an XmlAdapter for it.  The
> java generated from the WSDL has a field that's listed in that Adapter
> along with a "HashMap" that extends "AbstractMap", both in my
> namespace.
>
> The "HashMap" object has getters and setters based on the fieldName
> while the holder object for a List of my Entries is based on the
> method name. That is this class:
>
> @XmlRootElement
> public class AdRequest {
>   @XmlJavaTypeAdapter(QueryParametersAdapter.class)
>   private Map<String, String[]> m_queryParameters;
>   public Map<String, String[]> getQueryParameters() { ... }
>   public void setQueryParameters(Map<String, String[]>
> p_queryParameters) {} }
>
> Turns into this after wsdl2java:
>
> public class AdRequest  implements java.io.Serializable {
>     private mynamespace.HashMap m_queryParameters;
>     private mynamespace.AdRequestQueryParametersEntry[]
> queryParameters; }
>
> Where mynamespace.HashMap extends mynamespace.AbstractMap.
>
> Marshalling and unmarshalling works fine with my Map<String,String[]>
> values added via setQueryParameters(AdRequestQueryParametersEntry[]). 
> I'm just annoyed that this HashMap shows up.
>
> I've tried to annotate with XmlAccessType set to PUBLIC_MEMBER (the
> default) and PROPERTY but it hasn't helped me out.
>
> If I change the field name in my original AdRequest to
> "queryParameters" I get this error in my logs:
>
> Class has two properties of the same name "queryParameters"
> 	this problem is related to the following location:
> 		at public java.util.Map
> com.ladro.cxf.image.AdRequest.getQueryParameters() at
> com.ladro.cxf.image.AdRequest
> 	this problem is related to the following location:
> 		at private java.util.Map
> com.ladro.cxf.image.AdRequest.queryParameters at
> com.ladro.cxf.image.AdRequest
>
> which does make sense.
>
> Has anyone else seen this?  I've also tried marking the field as
> XmlTransient but then JAXB ignores the getters and setters.



-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog