I have a class called XmlSource which contains a collection of objects of type XmlSourceAudioLang, and the XmlSourceAudioLang class has a field called language which I need to marshal to XML, i.e. :
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlSource {
@XmlElement(name="original_audio_language", nillable=true)
protected Set<XmlSourceAudioLang> originalAudio;
}
and
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlSourceAudioLang {
@XmlElement(nillable = true)
private String language;
}
With this setup, JAXB generates a original_audio_language tag for each object in the collection:
<original_audio_language>
<language>Ukrainian</language>
</original_audio_language>
<original_audio_language>
<language>Russian</language>
</original_audio_language>
Is there a way to configure the binding so that there is only one parent original_audio_language tag ?
Assuming that you mean that you want this:
<original_audio_language>
<language>Ukrainian</language>
<language>Russian</language>
</original_audio_language>
Then try this:
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlSource {
@XmlElementWrapper(name="original_audio_language")
@XmlElement(name="language")
protected Set<XmlSourceAudioLang> originalAudio;
}
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlSourceAudioLang {
@XmlValue
private String language;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With