- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下简单的类:
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
@JsonIgnoreProperties({ "thirdField" })
public class Message {
private TypeA type;
private String producer;
//Getters and Setters
}
在我的测试课
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Test {
public void testMethd() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(MapperFeature.USE_ANNOTATIONS, true);
Class<T> instanceType = Message.class;
String msgBody = "{\"producer\": \"clientApp\", \"type\": \"aType\", \"thirdField\": []}";
objectMapper.readValue(msgBody, instanceType);
}
}
我想做的就是将上面的 json 字符串转换为 Message 类并忽略“thirdField”。但我不断得到
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "thirdField" (class Message), not marked as ignorable (2 known properties: , "type", "producer"])
最佳答案
您混合了 jackson 的不同版本。请注意,您从 org.codehaus.jackson.annotate
(版本 1.x)导入 JsonIgnoreProperties
当您使用 com.fasterxml.jackson.databind
(版本 2.x)中的 ObjectMapper
时。
关于jackson - JsonIgnoreProperties 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20986995/
我有以下简单的类: 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
我是一名优秀的程序员,十分优秀!