Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8007751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:55:53+00:00 2026-06-04T17:55:53+00:00

This is my XML file: <fields> <field mappedField="Num"> </field> <field mappedField="Type"> </field> </fields> I

  • 0

This is my XML file:

<fields>
    <field mappedField="Num">
    </field>
    
    <field mappedField="Type">      
    </field>    
</fields>

I created 2 classes to parse it (Fields.java and Field.java):

@XmlRootElement(name = "fields")
public class Fields {

    @XmlElement(name = "field")
    List<Field> fields = new ArrayList<Field>();
        //getter, setter
}

and

public class Field {

    @XmlAttribute(name = "mappedField")
    String mappedField;
    //getter,setter
}

But I get this exception:

[INFO] com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
[INFO]  at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66) ~[na:1.6.0_07]
[INFO]  at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:422) ~[na:1.6.0_07]
[INFO]  at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:270) ~[na:1.6.0_07]

I can’t understand why this exception rises. Exception is here:

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

I use JDK 1.6_0.0.7. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:55:54+00:00Added an answer on June 4, 2026 at 5:55 pm

    The exception is due to your JAXB (JSR-222) implementation believing that there are two things mapped with the same name (a field and a property). There are a couple of options for your use case:

    OPTION #1 – Annotate the Field with @XmlAccessorType(XmlAccessType.FIELD)

    If you want to annotation the field then you should specify @XmlAccessorType(XmlAccessType.FIELD)

    Fields.java:

    package forum10795793;
    
    import java.util.*;
    import javax.xml.bind.annotation.*;
    
    @XmlRootElement(name = "fields")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Fields {
    
        @XmlElement(name = "field")
        List<Field> fields = new ArrayList<Field>();
    
        public List<Field> getFields() {
            return fields;
        }
    
        public void setFields(List<Field> fields) {
            this.fields = fields;
        }
    
    }
    

    Field.java:

    package forum10795793;
    
    import javax.xml.bind.annotation.*;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Field {
    
        @XmlAttribute(name = "mappedField")
        String mappedField;
    
        public String getMappedField() {
            return mappedField;
        }
    
        public void setMappedField(String mappedField) {
            this.mappedField = mappedField;
        }
    
    }
    

    OPTION #2 – Annotate the Properties

    The default accessor type is XmlAccessType.PUBLIC. This means that by default JAXB implementations will map public fields and accessors to XML. Using the default setting you should annotate the public accessors where you want to override the default mapping behaviour.

    Fields.java:

    package forum10795793;
    
    import java.util.*;
    import javax.xml.bind.annotation.*;
    
    @XmlRootElement(name = "fields")
    public class Fields {
    
        List<Field> fields = new ArrayList<Field>();
    
        @XmlElement(name = "field")
        public List<Field> getFields() {
            return fields;
        }
    
        public void setFields(List<Field> fields) {
            this.fields = fields;
        }
    
    }
    

    Field.java:

    package forum10795793;
    
    import javax.xml.bind.annotation.*;
    
    public class Field {
    
        String mappedField;
    
        @XmlAttribute(name = "mappedField")
        public String getMappedField() {
            return mappedField;
        }
    
        public void setMappedField(String mappedField) {
            this.mappedField = mappedField;
        }
    
    }
    

    For More Information

    • http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following XML: <Library> <Item> <Field Name=Name>smooth</Field> <Field Name=File Type>mid</Field> <Field Name=File Size>60026</Field>
I have this xml file <?xml version=1.0 encoding=UTF-8?> <bo:C837ClaimParent xsi:type=bo:C837ClaimParent xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:bo=http://somelongpathHere/process/bo> <claimAux> ...
Let's say I have this XML file: <Names> <Name> <FirstName>John</FirstName> <LastName>Smith</LastName> </Name> <Name> <FirstName>James</FirstName>
I have this XML file I need to extract the HTML Code from mono
i have this xml file: <dist> <key>keynumber1</key> <string>value1</string> <key>keynumber2</key> <string>value2</string> <key>keynumber3</key> <string>value3</string> <key>keynumber4</key> <integer>value4</integer>
I have this XML file <bookstore> <test> <test2/> </test> </bookstore> and this XSD schema
I have this XML file , and I want to find these queries :
I am receiving this XML file which I would like to validate. Ideally I
I am using an XML file to store the values. This XML file can
I want to make an XPath query on this XML file (excerpt shown): <?xml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.