繁体   English   中英

杰克逊·梅珀(Jackson Mapper):写作时忽略某些属性?

[英]Jackson mapper: ignore certain properties when writing?

我使用JSON映射器从字符串中读取对象,然后从对象中写入字符串。 我希望仅在编写时才能忽略某些属性。 最简单的方法是什么?

在界面上,您可以使用@JsonIgnoreProperties(ignoreUnknown=true)批注忽略所有未指定的字段。

例如:

@JsonIgnoreProperties(ignoreUnknown=true)
public static interface Point {
    double getLatitude();

    double getLongitude();
}

这将忽略使用Point接口序列化的任何其他字段。

您可以使用@JsonProperty(access = Access.WRITE_ONLY)忽略要序列化的属性。

您可以在下面的链接中获取有关此属性的更多信息。

https://fasterxml.github.io/jackson-annotations/javadoc/2.8/com/fasterxml/jackson/annotation/JsonProperty.Access.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM