Tag: jackson

使用Jackson忽略JSON对象上的新字段

我正在使用Jackson JSON库将一些JSON对象转换为android应用程序上的POJO类。 问题是,JSON对象可能会改变,并且在应用程序发布的时候添加新的字段,但是现在当添加一个简单的string字段时,它将会被破坏,这可以被安全地忽略。 有没有办法告诉jackson忽略新增的领域? (例如在POJO对象上不存在)? 全球忽视将是伟大的。

我如何从jackson的一个自定义反序列化器中调用默认的反序列化器

我在Jackson的自定义反序列化程序中遇到问题。 我想访问默认序列化程序来填充我反序列化的对象。 在人口之后,我会做一些自定义的事情,但首先我想用默认的jackson行为反序列化对象。 这是我目前的代码。 public class UserEventDeserializer extends StdDeserializer<User> { private static final long serialVersionUID = 7923585097068641765L; public UserEventDeserializer() { super(User.class); } @Override @Transactional public User deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectCodec oc = jp.getCodec(); JsonNode node = oc.readTree(jp); User deserializedUser = null; deserializedUser = super.deserialize(jp, ctxt, new User()); // The previous […]

在Spring中configurationObjectMapper

我的目标是configurationobjectMapper的方式,它只是串行化的@JsonProperty注释的@JsonProperty 。 为了做到这一点,我遵循这个说明如何configurationobjectmapper。 我包含了这里描述的自定义对象映射器。 但是,当NumbersOfNewEvents类被序列化时,它仍然包含json中的所有属性。 有人有提示吗? 提前致谢 jackson1.8.0spring3.0.5 CustomObjectMapper public class CompanyObjectMapper extends ObjectMapper { public CompanyObjectMapper() { super(); setVisibilityChecker(getSerializationConfig() .getDefaultVisibilityChecker() .withCreatorVisibility(JsonAutoDetect.Visibility.NONE) .withFieldVisibility(JsonAutoDetect.Visibility.NONE) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.DEFAULT)); } } servlet.xml中 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <context:component-scan base-package="de.Company.backend.web" /> <mvc:annotation-driven /> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> […]

jacksonVS. Gson

在search了一些现有的JSON库之后,我终于find了这两个: jackson Google GSon 我对GSON有些偏袒,但networking上的一句话是GSon遭受了某种天体性能问题 (截至2009年9月)。 我正在继续我的比较; 在此期间,我正在寻求帮助来下定决心。

避免对未获取的惰性对象进行Jackson序列化

我有一个简单的控制器,返回一个用户对象,这个用户有一个属性坐标具有hibernate属性FetchType.LAZY。 当我尝试获取这个用户时,我总是要加载所有的坐标来获取用户对象,否则当jackson尝试序列化用户时抛出exception: com.fasterxml.jackson.databind.JsonMappingException:无法初始化代理 – 没有会话 这是因为jackson试图抓取这个无法取得的物体。 这里是对象: public class User{ @OneToMany(fetch = FetchType.LAZY, mappedBy = "user") @JsonManagedReference("user-coordinate") private List<Coordinate> coordinates; } public class Coordinate { @ManyToOne @JoinColumn(name = "user_id", nullable = false) @JsonBackReference("user-coordinate") private User user; } 和控制器: @RequestMapping(value = "/user/{username}", method=RequestMethod.GET) public @ResponseBody User getUser(@PathVariable String username) { User user = userService.getUser(username); return user; […]

如何使用jackson反序列化的对象数组

jackson的数据绑定文档表明,jackson支持反序列化“所有支持types的数组”,但我无法弄清楚这个确切的语法。 对于单个对象,我会这样做: //json input { "id" : "junk", "stuff" : "things" } //Java MyClass instance = objectMapper.readValue(json, MyClass.class); 现在对于一个数组我想这样做: //json input [{ "id" : "junk", "stuff" : "things" }, { "id" : "spam", "stuff" : "eggs" }] //Java List<MyClass> entries = ? 任何人都知道是否有一个神奇的失踪命令? 如果不是,那么解决scheme是什么?

jacksonJSON和Hibernate JPA问题的无限recursion

当试图将具有双向关联的JPA对象转换为JSON时,我不断收到 org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError) 我发现的是这个线程 ,基本上推荐避免双向关联。 有没有人有一个解决方法这个春季bug的想法? ——编辑2010-07-24 16:26:22 ——- Codesnippets: 业务对象1: @Entity @Table(name = "ta_trainee", uniqueConstraints = {@UniqueConstraint(columnNames = {"id"})}) public class Trainee extends BusinessObject { @Id @GeneratedValue(strategy = GenerationType.TABLE) @Column(name = "id", nullable = false) private Integer id; @Column(name = "name", nullable = true) private String name; @Column(name = "surname", nullable = […]

如果jackson在序列化过程中忽略某个字段的值是否为空,该怎么办?

jackson如何configuration为在序列化期间忽略字段值,如果该字段的值为空。 例如: public class SomeClass { // what jackson annotation causes jackson to skip over this value if it is null but will // serialize it otherwise private String someValue; }