JSON 中缺少父标签

发布于 2024-10-07 04:12:01 字数 366 浏览 0 评论 0原文

我将此 DTO 转换为 XML/JSON 并从我的 Web 服务向客户端发送响应。我们正在使用泽西岛。

@XmlRootElement(name = "response")
public class Response {

@XmlValue
private String value="true";
}

它已正确转换为 XML,

<response>true</response>

但 json 丢失了父标记, 它输出 true 而不是 response:true

有人有同样的问题吗?

I have this DTO to be converted to XML/JSON and send response to client from my web service. We are using Jersey.

@XmlRootElement(name = "response")
public class Response {

@XmlValue
private String value="true";
}

It is getting properly converted to XML,

<response>true</response>

but json is missing out the parent tag,
it is outputting true instead of response:true

Is anybody having the same problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟雨扶苏 2024-10-14 04:12:01

值不会随父名称而修改。一件事是元数据(标签),另一件事是数据,不会被修改。

Values don't get modified with the parent names. One thing is metadata (tags), and other thing is data, that doesn't get modified.

你对谁都笑 2024-10-14 04:12:01

这实际上是因为我们在输出 JSON 时省略了父标签。
就在这种情况下,省略父标签会导致问题,因为对象中只有一个值。

It is actually because we are omitting parent tag while outputing JSON.
Just in this case omitting parent tag is causing problem as there is only one value in the object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文