Avoid Jackson serialization on non fetched lazy objects

I finally found the solution! thanks to indybee for giving me a clue. The tutorial Spring 3.1, Hibernate 4 and Jackson-Module-Hibernate have a good solution for Spring 3.1 and earlier versions. But since version 3.1.2 Spring have his own MappingJackson2HttpMessageConverter with almost the same functionality as the one in the tutorial, so we don’t need … Read more

How do I call the default deserializer from a custom deserializer in Jackson

As StaxMan already suggested you can do this by writing a BeanDeserializerModifier and registering it via SimpleModule. The following example should work: public class UserEventDeserializer extends StdDeserializer<User> implements ResolvableDeserializer { private static final long serialVersionUID = 7923585097068641765L; private final JsonDeserializer<?> defaultDeserializer; public UserEventDeserializer(JsonDeserializer<?> defaultDeserializer) { super(User.class); this.defaultDeserializer = defaultDeserializer; } @Override public User deserialize(JsonParser jp, … Read more

serialize/deserialize java 8 java.time with Jackson JSON mapper

There’s no need to use custom serializers/deserializers here. Use jackson-modules-java8’s datetime module: Datatype module to make Jackson recognize Java 8 Date & Time API data types (JSR-310). This module adds support for quite a few classes: Duration Instant LocalDateTime LocalDate LocalTime MonthDay OffsetDateTime OffsetTime Period Year YearMonth ZonedDateTime ZoneId ZoneOffset

Configuring ObjectMapper in Spring

Using Spring Boot (1.2.4) and Jackson (2.4.6) the following annotation based configuration worked for me. @Configuration public class JacksonConfiguration { @Bean public ObjectMapper objectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true); return mapper; } }

Java 8 LocalDate Jackson format

I was never able to get this to work simple using annotations. To get it to work, I created a ContextResolver for ObjectMapper, then I added the JSR310Module (update: now it is JavaTimeModule instead), along with one more caveat, which was the need to set write-date-as-timestamp to false. See more at the documentation for the … Read more

How to tell Jackson to ignore a field during serialization if its value is null?

To suppress serializing properties with null values using Jackson >2.0, you can configure the ObjectMapper directly, or make use of the @JsonInclude annotation: mapper.setSerializationInclusion(Include.NON_NULL); or: @JsonInclude(Include.NON_NULL) class Foo { String bar; } Alternatively, you could use @JsonInclude in a getter so that the attribute would be shown if the value is not null. A more … Read more

How to use Jackson to deserialise an array of objects

First create a mapper : import com.fasterxml.jackson.databind.ObjectMapper;// in play 2.3 ObjectMapper mapper = new ObjectMapper(); As Array: MyClass[] myObjects = mapper.readValue(json, MyClass[].class); As List: List<MyClass> myObjects = mapper.readValue(jsonInput, new TypeReference<List<MyClass>>(){}); Another way to specify the List type: List<MyClass> myObjects = mapper.readValue(jsonInput, mapper.getTypeFactory().constructCollectionType(List.class, MyClass.class));

Infinite Recursion with Jackson JSON and Hibernate JPA issue

JsonIgnoreProperties [2017 Update]: You can now use JsonIgnoreProperties to suppress serialization of properties (during serialization), or ignore processing of JSON properties read (during deserialization). If this is not what you’re looking for, please keep reading below. (Thanks to As Zammel AlaaEddine for pointing this out). JsonManagedReference and JsonBackReference Since Jackson 1.6 you can use two … Read more