0

I have a class:

import javax.xml.bind.annotation.*;

@XmlRootElement
class Plansza 
{
    String tura;

    String b0;
    String b1;
    String b2;

    String b3;
    String b4;
    String b5;

    String b6;
    String b7;
    String b8;


    @XmlElement
    public String getTura()
    {
        return this.tura;
    }

    public void setTura(String tura)
    {
        this.tura = tura;
    }

    @XmlElement
    public String getB0()
    {
        return this.b0;
    }

    public void setB0(String b0)
    {
        this.b0 = b0;
    }

    @XmlElement
    public String getB1()
    {
        return this.b1;
    }

    public void setB1(String b1)
    {
        this.b1 = b1;
    }

    @XmlElement
    public String getB2()
    {
        return this.b2;
    }

    public void setB2(String b2)
    {
        this.b2 = b2;
    }

    @XmlElement
    public String geB3()
    {
        return this.b3;
    }

    public void setB3(String b3)
    {
        this.b3 = b3;
    }

    @XmlElement
    public String getB4()
    {
        return this.b4;
    }

    public void setB4(String b4)
    {
        this.b4 = b4;
    }

    @XmlElement
    public String getB5()
    {
        return this.b5;
    }

    public void setB5(String b5)
    {
        this.b5 = b5;
    }

    @XmlElement
    public String getB6()
    {
        return this.b6;
    }

    public void setB6(String b6)
    {
        this.b6 = b6;
    }

    @XmlElement
    public String getB7()
    {
        return this.b7;
    }

    public void setB7(String b7)
    {
        this.b7 = b7;
    }

    @XmlElement
    public String getB8()
    {
        return this.b8;
    }

    public void setB8(String b8)
    {
        this.b8 = b8;
    }   
}

that I want to serialize to XML and read such class from the XML file. However when I'm creating context:

JAXBContext context = JAXBContext.newInstance(Plansza.class);

it throws an IllegalAnnotationsException:

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
JAXB annotation is placed on a method that is not a JAXB property
    this problem is related to the following location:
        at @javax.xml.bind.annotation.XmlElement(name=##default, namespace=##default, type=class javax.xml.bind.annotation.XmlElement$DEFAULT, required=false, defaultValue=, nillable=false)
        at Plansza

I tried adding constructors, but nothing seems to work, stil getting the same exception.

EDIT Uploaded whole Plansza class code as requested.

0

1 Answer 1

1

One option would be to add the following annotation to the class

@XmlAccessorType(XmlAccessType.FIELD)

And then move the @XmlElement annotations onto the variables like this.

@XmlElement
String tura = null;

This will then use the annotated variables to generate your XML

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.