users@jaxb.java.net

Re: Absence of XmlAccessorType from 2.1 to 2.2 not working

From: Martin Grebac <martin.grebac_at_oracle.com>
Date: Wed, 09 Jan 2013 16:46:18 +0100

Hi,
  looks like an issue - would you please verify this against recent jaxb
standalone release and not successful file it as an issue with simple
testcase?

Thanks,
  MartiNG

On 12/19/12 10:08 AM, Luc wrote:
> Hello!
>
> I've been using the JAXB bundled with JavaSE (2.1) to
> marshal/unmarshal objects. These objects doesn't used the annotation
> @XmlAccessorType, only @XmlElement on that fields / methods which had
> to be marshalled.
> I use the javax.xml.bind.JAXB to do the un/marshalling.
>
> In example:
> public class ModelData {
>
> private Model model;
> private LinkedList<RegistrySample> samples;
>
> public ModelData() {
> samples = new LinkedList<RegistrySample>();
> }
>
> public void add(RegistrySample sample) {
> samples.add(sample);
> }
>
> @XmlElement(name = "RSample")
> public List<RegistrySample> getSamples() {
> return samples;
> }
>
> public void setSamples(List<RegistrySample> newSamples) {
> samples.clear();
> if (newSamples != null) {
> samples.addAll(newSamples);
> }
> }
>
> public void removeLast() {
> samples.removeLast();
> }
>
> @XmlElement(name = "Model")
> public Model getModel() {
> return model;
> }
>
> public void setModel(Model model) {
> this.model = model;
> }
>
> }
> (None of the other objects is annotated with JAXB, only this class)
>
> Now I am using a JavaEE container, which bundles JAXB 2.2, and the
> before code doesn't work: it is correctly marshalled, but when
> unmarshalling the object, the list is emtpy.
>
> But annotating the ModelData class with
> @XmlAccessorType(XmlAccessType.FIELD) and moving the @XmlElement
> annotations to fields, works properly.
>
> Is this change intentionally?
>
> Thanks in advance,
> --
> Lucas
>

-- 
Martin Grebac, SW Engineering Manager (Metro/JAXWS/JAXB RI)
Oracle Czech, Prague
http://blogs.oracle.com/mgrebac