1

I have two objects like Vehicle and Car. Vehicle contains List of Cars. And Car contains carId, Name and Model number. Now I have to form an xml like below.

<Vehicle>
     <Car>Audi</Car> 
     <Car>BMW</Car>
     <Car>Chevrolet</Car>
</Vehicle>

My Class are like below

    public class Cars {

    private Long id;
    private String name;
    private String code;
}

and ...

    public class Vehicals {

    private List<Cars> cars;
}

With these objects we can form XML like below.

<Vehicle>
     <Car>
         <name>Audi</name>
      </Car> 
     <Car>
         <name>BMW</name>
     </Car>
     <Car>
         <name>Chevrolet</name>
     </Car>
</Vehicle>

But here i should not show name tag. I should get directly like <car>Audi</Car>. How can i achieve this?

Thanks in advance Tej.

1 Answer 1

1

Use @XmlValue.

Try:

@XmlValue
private String name;

An @XmlTransient on other properties. See also @XmlElementWrapper.

Not the answer you're looking for? Browse other questions tagged or ask your own question.