Skip to main content

@XmlJavaTypeAdapter Problems..

1 reply [Last post]
bhupiss
Offline
Joined: 2006-04-28
Points: 0

While running schemagen I got the error
error: java.util.Currency does not have a no-arg default constructor
this problem is related to the following location:
at java.util.Currency
at com.tickets.common.util.Money.getCurrency (Unknown Source)
at com.tickets.common.util.Money (Unknown Source)

While searching forums I found that there is soln to use XmlAdapter as mentioned on http://weblogs.java.net/blog/kohsuke/archive/2005/09/using_jaxb_20s.html

If I add the @XmlJavaTypeAdapter(CurrencyAdapter.class) to the culprit class it works..However I have too many classes having this description.

I am intrested in adding this annotation to the package-info.java...
However
@XmlJavaTypeAdapter(value=CurrencyAdapter.class,type=Currency.class)
package com.tickets.common.util;

this annotaion gives compile errors ...as

"The annotation @XmlJavaTypeAdapter is disallowed for this location"

I am using the latest jar of JAXB implementation

Any Suggestions...

Inder

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kohsuke
Offline
Joined: 2003-06-09
Points: 0

You must be using an old JAXB RI. The latest XmlJavaTypeAdapter source code says:
[code]
@Retention(RUNTIME) @Target({PACKAGE,FIELD,METHOD,TYPE,PARAMETER})
public @interface XmlJavaTypeAdapter {
[/code]
so it's clearly allowed on a package. Can you download the nightly of the JAXB RI and try it again?

Alternatively, wrap that into XmlJavaTypeAdapter[b]s[/b] annotation.