I'm not sure how to best explain this, so this may be a bit long, please bear with me.
Let's say I have a java bean with a bunch of properties:
public interface Customer {
public String getFirstName();
public String getLastName();
public Address getAddress(); // embedded bean with its own properties
... // lots more
}
There's a corresponding implementation, obviously, plus appropriate setters are defined as well (though setters may not be exposed in the interface for some properties).
There's a service (POJO interface + implementation) that defines a bunch of operations that can be performed on customers (CRUD, some find() queries, etc...). Service is bootstrapped via Spring and the whole thing works fine locally and via RMI.
Now I have a client (iPhone app) which needs access to a small subset of functionality exposed via above API - subset both in terms of service operations and API properties. The idea is to expose this subset via REST-style API:
GET /services/customers/1234
returns
<customer>
<firstName>Homer</firstName>
<lastName>Simpson</lastName>
<city>Springfield</city>
</customer>
or maybe even
<customer firstName="Homer" lastName="Simpson" city="Springfield" />
The question is - how do I go about doing this? I've (briefly) looked at JAXB / CXF / Jersey and it looks like I'd have to define a schema, generate a bunch of classes based on it and copy data from my API entities to those classes. Is there a way to avoid all that?
Ideally I'd like to annotate the appropriate properties in my API entities and have them (and only them) marshalled "automagically". I'm ok with writing dedicated interface / implementation for the web service endpoint if needed; annotating the existing one would be even better.
The other (more pressing) question is - am I doing something stupid? Is there a simpler and / or better way? Last time I've worked with web services was Axis 1.1 times and last time I've worked with iPhone was never :-) so any pointers will be much appreciated.
Update: To clarify - I'm looking for the simplest way to marshall a subset of javabean properties to XML (or JSON maybe?) without having to write / generate an additional class to represent said subset of properties. The above example is an oversimplification, in reality the API is quite extensive with many classes involved. I really want to avoid duplication if possible.