我有以下 POJO(在构造函数等内):
public class GlobalData implements Serializable {
//constructors getters and setters
@org.codehaus.jackson.annotate.JsonProperty("size-guide")
private List<SizeGuide> sizeGuides;
}
属性 sizeGuide 标记为 JsonProperty ,因此当我使用 ObjectMapper 对其进行编码时,该属性将出现在名为 size-guide 而不是 sizeGuide 的 JSON 中。
但是,这不起作用,当我将 ObjectMapper.write 值作为 String 方法执行时,该属性不会“更改”他的名称,它仍然显示为 sizeGuide。
有什么提示吗?
最佳答案
您需要使用
public class GlobalData implements Serializable {
//constructors getters and setters
@com.fasterxml.jackson.annotation.JsonProperty("size-guide")
private List<SizeGuide> sizeGuides;
}
关于Java JsonProperty 注释在编码时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59821449/