Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 643365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:16:29+00:00 2026-05-13T21:16:29+00:00

I’m not sure how to best explain this, so this may be a bit

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:16:30+00:00Added an answer on May 13, 2026 at 9:16 pm

    Googling jaxb interface seems to indicate interfaces are a pain to work with in JAXB, as seen in this java.net blog post and another stackoverflow question.

    It may be easier if your POJO is a class rather than an interface. I’m using RESTEasy (another JAX-RS implementation) with JAXB and I only need to annotate my POJO class with @XmlRootElement. On the other side, I’ve written custom http client code to marshall/unmarshall the same annotated class with JAXB (would be automagic with RESTEasy client proxy framework if I can use that). Note that I don’t have a schema defined, but I can get away with a lot since I’m in control of both sides of the RESTful web service.

    Jersey has a client API you might want to take a look at. CXF also has a front-end / client API including a proxy-based mechanism similar to RESTEasy.

    Take a look at the RESTful Java with JAX-RS book which covers the following that I’ve found helpful:

    • REST service concepts
    • overview of the various implementations including client API support
    • code examples

    Example controller:

    @GET
    @Produces( { MediaType.APPLICATION_XML })
    @Path("/customers/{id}")
    public Customer getCustomer(@PathParam("id") int id) {
        ...
        return customer;
    }
    

    Example POJOs:

    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Customer {
      Address address;
      String name;
    
      // annotate with XmlTransient to prevent mapping this property/type to XML
      @XmlTransient
      String ssn;
      ...
    }
    
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Address {
      String planet;
      ...
    }
    

    XmlTransient Java doc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a JSP page retrieving data and when single or double quotes are
I have just tried to save a simple *.rtf file with some websites and
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm looking for suggestions for debugging... If you view this site in Firefox or
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.