users@jaxb.java.net

getting POJO attributes as element content?

From: Jamie <jdennis_at_ipass.net>
Date: Wed, 22 Nov 2006 14:11:47 -0500

Hi -

I'm in need of some guidance on how to solve a couple of problems I'm
running into using JAXB to marshal our POJOs to meet an existing schema.
I'll send out a separate email for the other issue, but one of the
problems I'm running into is I have code like this:

Class Garage {
  List<Car> getCars() {
     return carList;
  }
}

Class Car extends Vehicle {
  String getName() {
     return "Honda Accord";
  }
  int getNumberOfDoors() {
     ...
  }
}

I want the Xml snippet for this to marshal out to:
<Garage>
  <Car>Honda Accord</Car>
</Garage>

I know that one way to do it is to annotate getCars as transient, write
a new method getCarNames and annotate that to the Car element... But I'm
looking for a hopefully more elegant solution simply involving
annotating my existing class(es).


Thanks!
-Jamie