users@jaxb.java.net

mapping using annotations without compiling a schema

From: Dmitri Colebatch <colebatchd_at_gmail.com>
Date: Mon, 20 Jun 2005 17:59:17 +1000

Hi all,

I'm sure what I want to do is possible, but I'm struggling finding the
documentation on the subject. My situation is this - I have a bunch
of classes that roughly map to a schema. The classes and the schema
have been developed separately, but with knowledge of each other.
I've been given a list of what field needs to map to what element, so
that work is all done. What I'd like to do is just add annotation to
the existing classes so they are marshalled out to the appropriate
elements.

My problem is that all the doco pretty well assumes that you are
compiling a schema (see figure 1-1 in
http://java.sun.com/webservices/docs/1.1/tutorial/doc/IntroWS6.html).
Because I dont want to do this I'm struggling to see how all the
annoations fit together. I'm reading the javadoc on the annotations
package, which is helpful, but I think what I'm missing is a good
guide on the default behaviour, so I then know what I need to
customize.

For example, I've got a little class like this:

@XmlRootElement(name = "DealMsg", namespace = "urn:deal")
public class Deal
{
        @XmlElement(name = "DealStatus", namespace = "urn:deal", type = String.class)
        private String status = "In progress";

}

which goes nicely into

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DealMsg xmlns="urn:deal">
    <DealStatus>In progress</DealStatus>
</DealMsg>

but when I add my getStatus/setStatus methods I get

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:DealMsg xmlns:ns2="urn:deal">
    <ns2:DealStatus>In progress</ns2:DealStatus>
    <status>In progress</status>
</ns2:DealMsg>

which isn't what I want.

Could someone point me at the appropriate source of doco for doing
this sort of thing? I'll admit to not having read the spec, but I
have tried to find relevant parts without too much success. Is it
possible to do this without changing the schema?

cheers, and thanks.
dim