- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 POJO,其中包含一个字段需要输出到带有标签名称“class”的 XML。
使用 Jersey 2.0,如果客户端请求 JSON 响应,JSON 对象会正确输出属性名称“class”。
但是,如果客户端请求 XML 输出,Jersey 会失败并出现 HTTP 500 内部错误。
检查了导致错误的语句是
@XmlElement(名称 = "类")
private int vclass;
删除 XmlElement 注释并允许 XML 使用 vclass 作为标记名称工作正常。
我如何指示 JAXB 使用 class 作为标签名称??
最佳答案
Why “class” cannot be use as tag name in JAXB
您可以在 JAXB 中使用“class”作为标签名称。
默认情况下,JAXB 将公共(public)属性视为已映射。由于您注释了一个字段,您很可能会收到有关重复映射属性的异常。
Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Class has two properties of the same name "vclass"
this problem is related to the following location:
at public int forum27241550.Foo.getVclass()
at forum27241550.Foo
this problem is related to the following location:
at private int forum27241550.Foo.vclass
at forum27241550.Foo
您将以下内容发布为 answer :
Finally found out what's wrong.
Don't know why the annotation in variable declaration statement will cause problem.
Putting the @XmlElement annotation in the setter method work fine.
当您将注释移动到属性时,该字段不再被视为已映射,因此不存在重复映射问题。
要注释字段,您应该在类上使用 @XmlAccessorType(XmlAccessType.FIELD)
。
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;
}
}
关于java - 为什么 "class"不能用作 JAXB 中的标记名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27241550/
我有以下查询: SELECT I.InsuranceID FROM Insurance I INNER JOIN JobDetail JD ON I.AccountID = JD.AccountID
我想在 SwiftUI 布局中将此函数用作具有不可变值的模板,但得到错误 Result of call to 'padding' 未使用: func keys (padding: CGFloat, t
直到最近我才使用 View 的标签元素,此后发现了一些很酷的用途。我遇到了一个不寻常的问题,希望有人能回答。这可能比 Android 更通用,但我不确定。它与 Java 如何处理 Integer 类有
这个问题在这里已经有了答案: What is the purpose of the var keyword and when should I use it (or omit it)? (19 个回
我有以下脚本(见下文)。我有两个问题: 1.在 Knockoutjs 的上下文中,下面这行是什么意思? ko.observable(null); 2.如何调用这里尚未定义的函数: that.activ
Java 社区中是否存在一种使用 with-repect-to 在方法中使用多个返回的思想流派,如下所示: public SomeClass someMethod(int someValue) {
我一直在尝试为我的网站创建一个小型社交媒体栏。出于某种原因,我无法计算出我想用来创建 Sprite 的图像无法加载。我还应该提一下,我在背景图像不显示方面遇到过类似的问题。 HTML调用是这样的:
我正在尝试使用 std::pair 枚举值作为 unordered_map 容器的键,但我在定义自定义哈希函数时遇到困难。 我尝试了以下方法: // Enum and pair declaration
我正在学习 JS/JQuery 以及匿名函数和闭包。我见过这样的例子: $('.button').click(function(){ /* Animations */ /* Other
我正在尝试使用菜单列表来浏览我的应用程序。尽管应用程序和路由运行良好,但我使用这段代码在控制台中收到了一些警告: {props.itemList.map((item, index) =>(
我只是想创建一个简单的测试,我在其中使用 DelegateHandlers 来实例化一个 HttpClient 而无需引入 Asp.net Core 包。我有 2 个删除处理程序 Throttling
我是answering another question在这里,用户有一个 ListView与 ItemsSource包含 UserControls .我说我不会推荐它,并被问为什么。 这真的让我很惊
我安装了3.5.2和 3.5.3使用 pyenv 的版本。 # pyenv versions * system (set by /usr/local/pyenv/version) 3.5.2
我正在使用 android studio 制作统一插件,但这里有问题。一些 SDK 提供仅使用 AppcompatActivity 来制作 fragment 但我的MainActivity , 正是
我在 Laravel 中使用 whereHas 来构建查询: })->whereHas('results', function ($query) use ($issued, $mode, $reque
我有一个 5Gb .dat 文件(> 1000 万行)。每行的格式如 aaaa bb cccc0123 xxx kkkkkkkkkkkkkk或 aaaaabbbcccc01234xxxkkkkkkkk
我有一个消费者类,它采用 NSInputStream 作为参数,它将被异步处理,并且我想推送来自生产者类的数据,该生产者类要求它提供 NSOutputStream 作为其输出源。现在我如何设置一个缓冲
我正在尝试使用 ENVs在 Symfony2 中设置我的参数。标量值很简单,但我有一些参数是数组,我需要使用 ENV 以某种方式设置它们。 有问题的参数: parameters: redis.se
在我的类作业中,我已经成功地做到了这一点,但只是在非常简单的程序中。今天,我有一个更复杂的程序,在我将 DEBUG 定义为一个符号后,Eclipse 做了可怕的笨拙的事情,并且在我删除定义后这些可怕的
我目前有 2 个复选框类别、一个下拉列表和一个表单中的提交按钮。该按钮应保持“禁用”状态,直到选中 A 类的一个复选框和选中 B 类选项之一并选择选择列表中的一个选项。它适用于复选框(当我在没有列表的
我是一名优秀的程序员,十分优秀!