Ok I believe my problem is due to the fact there is no way to specify a
different namespace in the base class for every subclass at runtime.
So I guess it is not that bad to provide a default getter in the base class,
then to explicitly override the getter and annoted it with @XmlElement whenever
you want the field to be serialized.
So my solution for this is alike:
public class AbstractEntity {
private String createdBy;
public String getCreatedBy() {
return createdBy;
}
}
@XmlRootElement()
public final class Enterprise extends AbstractEntity {
@XmlElement()
@Override public String getCreatedBy() {
return super.getCreatedBy();
}
}
Please let me know if there is a better path.
----- Original Message ----
From: Pierre Radermecker <pradermecker_at_yahoo.ca>
To: users_at_jersey.dev.java.net
Sent: Tue, August 24, 2010 4:57:13 PM
Subject: Jersey and schema prefix
Hi,
I have been searching for this finding bits of solutions but I don't seem to be
able to make it work somehow.
By default Jaxb will generate a schema prefix such as "ns2". Jaxb does not seem
to care at all about the prefix of my package-info file:
@XmlSchema(
namespace = "
http://myurl/ns/enterprise",
xmlns = {_at_XmlNs(prefix = "ent", namespaceURI =
"
http://myurl/ns/enterprise")},
elementFormDefault= XmlNsForm.UNQUALIFIED
)
Is this a kind of bug ? Apparently there is a way to set a custom prefix using
com.sun.xml.bind.marshaller.NamespacePrefixMapper but I have no idea how to do
that inside Jersey (with Guice).
I would not mind removing any kind of prefix completely. I can easily manage
this by removing the xmlns declaration above but as soon as I create an ancestor
to a resource, if the ancestor is not in the same package and if the ancestor
contains some @XmlElement declaration I have got a prefix generation ... I find
it a bit awkward to define "getters" in the subclass to avoid @XmlElement
declaration in the base class.
@XmlRootElement()
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
public final class Enterprise extends AbstractEntity {
....
}
public class AbstractEntity {
@XmlElement
private String createdBy;
}
Thanks for your help.
- Pierre