java - Why "class" cannot be use as tag name in JAXB -


i have pojo contain field need output xml tag name "class".

using jersey 2.0, if client request json response, json object output correctly attribute name "class".

however, if client request xml output, jersey fail http 500 internal error.

checked statement causing error is

@xmlelement(name = "class") private int vclass;

removing xmlelement annotation , allow xml use vclass tag name work fine.

how instruct jaxb use class tag name ??

why “class” cannot use tag name in jaxb

you can use "class" tag name in jaxb.


what issue hitting

by default jaxb treats public properties mapped. since annotated field getting exception duplicate mapped property.

exception in thread "main" com.sun.xml.internal.bind.v2.runtime.illegalannotationsexception: 1 counts of illegalannotationexceptions class has 2 properties of same name "vclass"     problem related following location:         @ public int forum27241550.foo.getvclass()         @ forum27241550.foo     problem related following location:         @ private int forum27241550.foo.vclass         @ forum27241550.foo 

why did fixed it

you posted following answer:

finally found out what's wrong.

don't know why annotation in variable declaration statement cause problem.

putting @xmlelement annotation in setter method work fine.

when moved annotation property field no longer considered mapped, there no duplicate mapping problem.

how keep annotation on field

to annotate field should use @xmlaccessortype(xmlaccesstype.field) on class.

import javax.xml.bind.annotation.*;  @xmlrootelement @xmlaccessortype(xmlaccesstype.field) public class foo {      @xmlelement(name = "class")     private int vclass;      public int getvclass() {         return vclass;     }      public void setvclass(int vclass) {         this.vclass = vclass;     }  } 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -