jackson-databind

Configure a Jackson's DeserializationProblemHandler in Spring environment [duplicate]

天大地大妈咪最大 提交于 2019-12-02 03:54:09
This question already has an answer here: Can't set ProblemHandler to ObjectMapper in Spring Boot 1 answer As I understood, Spring is already providing a bean for Jackson ObjectMapper . Therefore, instead of creating a new bean, I'm trying to customize this bean. From this blog post , and then this Github project I used Jackson2ObjectMapperBuilder bean to achieve this customization. @Bean public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder(ApplicationContext context) { Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); builder.findModulesViaServiceLoader(true);

Serializing a field as json

淺唱寂寞╮ 提交于 2019-12-01 22:43:08
I need to send a JSON body to REST service. Unfortunately, service is quite old and I need to send a POJO, containing JSON string field. So it looks like this: class SomeData { int id; SomePojo jsonField; ... } So SomeData should be sent like this: {'id': 1, 'jsonField': some_json_string} I haven't found any Jackson magic annotation to make it works and I've got a doubt it can be made somehow because of type erasure in Java and it may not be possible to write custom serializer for this purpose but I'm not sure. Could you please suggest any idea of how I can make it work or workaround the issue

Lombok 1.18.0 and Jackson 2.9.6 not working together

断了今生、忘了曾经 提交于 2019-11-29 12:15:28
问题 The deserialization is failing after the update. I updated my micro-service from Spring 1.5.10.RELEASE to Spring 2.0.3.RELEASE and also updated the lombok from 1.16.14 to 1.18.0 and jackson-datatype-jsr310 from 2.9.4 to 2.9.6 . The JSON string - {"heading":"Validation failed","detail":"field must not be null"} The Class - @Data @JsonInclude(JsonInclude.Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class ErrorDetail { private final String heading; private final String

Jackson/Hibernate, meta get methods and serialization

我是研究僧i 提交于 2019-11-28 11:53:02
问题 We have lot of hibernate entity classes with nested relationships. I'm trying to find best way to convert given entity to equivalent json format. I know about JsonIgnore, Jackson mixins and JsonFilters and have been experimenting with those. Challenges we are facing are as following Objects related to each other using OneToMany/JoinColumn or similar annotations - creates infinite recursion. Utility or meta methods. Jackson seems to be going by getter methods and not by fields. Some of the

Jackson, deserialize class with private fields and arg-constructor without annotations

独自空忆成欢 提交于 2019-11-28 09:53:26
It is possible to deserialize to a class with private fields and a custom argument constructor without using annotations and without modifying the class, using Jackson? I know it's possible in Jackson when using this combination: 1) Java 8, 2) compile with "-parameters" option, and 3) the parameters names match JSON. But it's also possible in GSON by default without all these restrictions. For example: public class Person { private final String firstName; private final String lastName; private final int age; public Person(String firstName, String lastName, int age) { this.firstName = firstName

Can't set ProblemHandler to ObjectMapper in Spring Boot

一笑奈何 提交于 2019-11-27 07:15:18
问题 I tried to add custom problem handler to object mapper with Jackson2ObjectMapperBuilderCustomizer: @Bean public Jackson2ObjectMapperBuilderCustomizer customizer() { return new Jackson2ObjectMapperBuilderCustomizer() { @Override public void customize(Jackson2ObjectMapperBuilder builder) { ObjectMapper m = builder.build(); m.addHandler( new DeserializationProblemHandler() { @Override public boolean handleUnknownProperty(DeserializationContext ctxt, JsonParser p, JsonDeserializer<?> deserializer

Jackson, deserialize class with private fields and arg-constructor without annotations

一曲冷凌霜 提交于 2019-11-27 03:15:12
问题 It is possible to deserialize to a class with private fields and a custom argument constructor without using annotations and without modifying the class, using Jackson? I know it's possible in Jackson when using this combination: 1) Java 8, 2) compile with "-parameters" option, and 3) the parameters names match JSON. But it's also possible in GSON by default without all these restrictions. For example: public class Person { private final String firstName; private final String lastName;