- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我偶然发现了一些添加了 JsonIgnoreProperties 的代码到类中不存在但存在于 JSON
中的属性,例如:
@JsonIgnoreProperties({"ignoreprop"})
public class VO {
public String prop;
}
当 JSON
为
{ "prop":"1", "ignoreprop":"9999"}
我想知道忽略属性在性能方面是否有任何优势,还是只是冗余代码?
Annotation that can be used to either suppress serialization of properties (during serialization), or ignore processing of JSON properties read (during deserialization).
编辑
忽略所有特定属性是否有优势(有@JsonIgnoreProperties(ignoreUnknown=true)
)?
最佳答案
I wonder if ignoring properties has any advantage
是的,它被大量用于服务的前向兼容性。假设您有服务 A 和 B。目前 A 使用一些 JSON 对象向 B 发送请求。
现在您想要支持 JSON 中的新属性。如果你有这个特性,你就可以让 A 在 B 知道如何处理之前开始发送新的属性。 解耦这两个服务的开发过程。
ignoring specific property over all
这种情况确实有一些小的性能优势。首先,它不会尝试解析这个可以是简单字符串或复杂对象/数组的属性。其次,它可以帮助您避免处理异常。认为以下所有都是有效的调用,你只关心 prop
:
{ "prop":"1", "ignoreprop":"9999"}
{ "prop":"1", "ignoreprop":{ "a": { "key": "value", "foo": false }}}
{ "prop":"1", "ignoreprop":[1,2,3,4,5,6..... 1000000]}
关于java - 使用 JsonIgnoreProperties 特定属性反序列化属性仅存在于 JSON 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53389302/
我有以下简单的类: import org.codehaus.jackson.annotate.JsonIgnoreProperties; @JsonIgnoreProperties({ "thirdF
我想忽略一些属性(我从 UI 获得的),比如 过滤值 0、过滤值 1、过滤值 2 等 但是我确实从 UI 中得到了这个计数 即如果过滤器计数 = 3我知道,会有过滤值0、过滤值1、过滤值2 是否可以动
我当前忽略 JPA 实体已知属性的注释是: @JsonIgnoreProperties({"hibernateLazyInitializer", "handler","created","update
有没有办法让 @JsonIgnoreProperties 成为目标嵌套属性? 类似于下面的代码: public class ParentObject() { @JsonIgnoreProper
我希望能够忽略未知属性以及特定字段。我知道如何在单独的注释中做到这一点: @JsonIgnoreProperties({"origin" }) @JsonIgnoreProperties(ignore
我有这样的 pojo: @JsonIgnoreProperties(ignoreUnknown = true) public class SNAPIResponse { public Stri
下面这段代码在 Java Spring Boot 中有什么作用? @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) 最佳答案
我试图允许序列化我的对象,但不包括某些字段。假设我有一个类: class UserInfo { String userName; String password;
我在将 @JsonIgnoreProperties 与 kotlin 一起使用时遇到问题。我需要忽略多个属性,并且我看到许多教程/SO 问题,使用 java,通常你会这样做: @JsonIgnoreP
我有以下实体,我将其用作对 Controller 的请求之一的目标 POJO: Entity @Table(name="user_account_entity") @JsonIgnorePropert
RestTemplate的getForObject方法将忽略类上的@JsonIgnoreProperties(ignoreUnknown = true)批注。 例如。为了 @JsonIgnorePro
目前Spring Boot示例应用创建正常。在请求中,如果有任何未知字段到来,那么我们需要抛出一个错误。 为此使用了 @JsonIgnoreProperties(ignoreUnknown = fal
目前Spring Boot示例应用创建正常。在请求中,如果有任何未知字段到来,那么我们需要抛出一个错误。 为此使用了 @JsonIgnoreProperties(ignoreUnknown = fal
在我的项目中,有一些类应该通过 jackson 进行反/序列化。它们都应该忽略未知的属性,因此我用 @JsonIgnoreProperties(ignoreUnknown = true) 注释它们。
在 Jackson 中,您可以通过在类级别提供注释 @JsonIgnoreProperties 来忽略属性,并且不在实际 JSON 中的属性不会从 Java 类序列化/反序列化。如果我们使用 GSON
我需要序列化 - 反序列化代码中现有的 Java POJO。 POJO 很大+它在层次结构中几乎没有父类。该代码在内部使用 spring 和 Jackson。我开始通过修复 getter-sett
我偶然发现了一些添加了 JsonIgnoreProperties 的代码到类中不存在但存在于 JSON 中的属性,例如: @JsonIgnoreProperties({"ignoreprop"}) p
我有两门课: @JsonIgnoreProperties(values="foo", allowGetters = true) public class Parent { String foo;
我正在使用 Jackson 2,但需要使用一个使用 Jackson 1(codehause) 的库,并调用其远程服务器。 但是由于客户端-服务器版本不匹配,服务器端返回客户端模式类无法识别的字段。所以
我有一个名为“BaseEntity”的类。从基础实体扩展的其他实体。 基础实体 @MappedSuperclass public abstract class BaseEntity { @Id
我是一名优秀的程序员,十分优秀!