Java的Jsonproperty
我在其他问题中发现了这个问题,但我认为它们太老了,他们不再工作了。
我正在消耗返回JSON的外部服务,并且想将其转换为我自己的服务中的对象。同时,此对象将是我的服务输出。
我的问题是使用jsonproperty,我想重命名我在JSON中收到的一些变量,但它不起作用,以某种方式可以在调试器中起作用,但在返回的对象中不起作用。
import com.fasterxml.jackson.annotation.JsonProperty;
public class MyClass {
@JsonProperty("NAME")
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
因此,我期望收到的是一个带有关键名称的JSON,但是我得到了一个关键名称,
// Expected:
{
"name": "John"
}
// Received
{
"NAME": "John"
}
因为我可以在其他解决方案中阅读的问题是导入,有些人正在使用旧的jsonproperty库,但是我正在使用期望的一个。
我还要检查什么可以使它起作用?
I found this question in other questions, but I think they are too old and they are not working anymore.
I'm consuming an external service that returns a JSON and I want to convert it into an object in my own service. At the same time, this object will be my service output.
My problem is using JsonProperty, I would like to rename some variables I'm receiving in my json, but it is not working, somehow it works in debugger, but not in the returned object.
import com.fasterxml.jackson.annotation.JsonProperty;
public class MyClass {
@JsonProperty("NAME")
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
So what I expect to receive is a json with a key name, but I get one with key NAME
// Expected:
{
"name": "John"
}
// Received
{
"NAME": "John"
}
As I can read in other solutions the problem is the import, some people are using old JsonProperty library, but I'm using the expecting one.
Is there anything else I should check to make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,您正在使用注释,使响应将“名称”作为钥匙。这完全可以重命名JSON响应键。因此,删除它会让您将钥匙作为“名称”获取
So you are using an annotation making the response to have that "NAME" as a key. This is solely there to rename the JSON response keys. So removing it will let you get the key as "name"