views:

35

answers:

1

I have a XSD file I'm using to generate JAXB classes for a RESTful API I am working on.

I have two classes. An Appointment and a Person. A Person has an Appointment. I'd like to end up with XML like this:

<Appointment>
    <Person id="12345">Billy Bob</Person>
    ...
</Appointment>

So, that on the far end I an just fetch Person if I need more information or just use the content provided if that would be sufficient (like Name). Don't want to waste a round trip to just get the name.

I'd really like to keep the XSD -> Java Classes path if at all possible. I don't mind using Adapters, but I'd like everything to ultimately be driven by the XSD since it makes things very easy to change as we evolve.

Maybe an adapter is the way to go for this?

UPDATE

Here is what I would really like to accomplish.

  1. Define an XSD, where on the Java side of the house I have an Appointment which references a Person object. So, I can do something like appt.getPerson().

  2. When I serialize the Appointment object, The Person element isn't a seralization of the entire Person object.

    <Person> <firstName>...</firstName></Person>

but rather something like this: <Person ref="/Person/12345">Bob Smith</Person>.

This allows me to fetch an appointment gathing the information I need to display the appointment (the person's name) but still easily give me access to the Person associated with the appointment if needed.

The other way to solve this would be to include personId element and a personName element and populate both, but it wouldn't give me the appt.getPerson() support I am looking for on the java side.

Hopefully this clarifies the question and will solicit some additional responses.

+1  A: 

This is now a duplicate of this question. I answered it there.

xcut