相关疑难解决方法(0)

@XmlElement是否可以使用非标准名称注释方法?

这就是我正在做的事情:

@XmlType(name = "foo")
@XmlAccessorType(XmlAccessType.NONE)
public final class Foo {
  @XmlElement(name = "title")
  public String title() {
    return "hello, world!";
  }
}
Run Code Online (Sandbox Code Playgroud)

JAXB抱怨:

com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 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(nillable=false, name=title, required=false, defaultValue=, type=class javax.xml.bind.annotation.XmlElement$DEFAULT, namespace=##default)
        at com.example.Foo
Run Code Online (Sandbox Code Playgroud)

该怎么办?我不希望(也不能)重命名该方法.

java jaxb jaxb2

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

java ×1

jaxb ×1

jaxb2 ×1