Questions tagged [jackson2]

Use this tag only for questions specifically related to version 2 of the Jackson library

Jackson version 2 is a Java serialization and deserialization API typically used for reading and writing JSON, although other data formats such as Avro, CBOR, CSV, Java Properties, Protobuf, Smile, XML, and YAML are also supported.

464 questions
4
votes
1 answer

How to use @JsonTypeInfo, @JsonSubType to determine a field type based on a sibling field's value?

Say I have a class structure like this :- class ShapeRequest { ShapeInfo shapeInfo; Shape shape; static class ShapeInfo { String shapeName; String shapeDimension; } static abstract class Shape { } …
Jerald Baker
  • 1,121
  • 1
  • 12
  • 48
4
votes
1 answer

JsonTypeInfo not shown in response whit Pageable

I have an abstract class @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "_type", visible = true, include = As.EXISTING_PROPERTY) @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @JsonSubTypes({ @Type(value =…
Matija Župančić
  • 1,080
  • 2
  • 11
  • 21
4
votes
2 answers

Jackson global settings to deserialise array to custom list implementation

By default, Jackson is using java.util.ArrayList to deserialise a JSON array. Instead of this, I want to use a custom implementation. For example, Guava ImmutableList if value is present, or Collection.emptyList() if JSON array is empty or null. I…
Łukasz Woźniczka
  • 1,625
  • 3
  • 28
  • 51
4
votes
2 answers

How to configure Jackson XmlMapper to use data types from xml schema

I have a xml message that needs to be converted to json message format. The xml message has xml schema defined that has type information for the elements. However, the resulting json has all the values as text values instead of boolean/number as…
user1573133
  • 904
  • 1
  • 9
  • 23
4
votes
1 answer

Jackson: JsonIdentityInfo serialises depth of only one child

For some reason JsonIdentityInfo serialises the depth of one child but not the other. My example: @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "id") class A { private long id; private B last; //…
Sterling Duchess
  • 1,970
  • 16
  • 51
  • 91
4
votes
1 answer

@ControllerAdvice not triggered for Jackson errors

I have a @RestController which has a POST method and if I get a data error saving, then my @ControllerAdvice fires; however, if my error is from Jackson deserialization which is triggered by the @Valid annotation, it is never reaching the…
cicit
  • 581
  • 5
  • 24
4
votes
0 answers

How to rename a json property only inside @JsonView?

I want to rename a json field, but only within a specific @JsonView. Is that possible at all? public class PersonDTO { @JsonView(View.Specific.class) private String personname; static class View { interface Specific { …
membersound
  • 81,582
  • 193
  • 585
  • 1,120
4
votes
2 answers

Why Jackson’s ObjectMapper methods take raw TypeReference

Jackson 2 ObjectMapper class defines numerous generic methods for deserializing JSON strings, byte arrays, files, etc. to given Java types. Target type is given in an argument to those methods. Eg. a type may be given as a Class, like in the…
silmeth
  • 680
  • 1
  • 8
  • 22
4
votes
1 answer

How to prevent ALL of Jackson auto-config in Spring?

Context I have a situation where I do not control the main of the application nor the libraries on the class path. I am extending (via a plug-in API) an existing Swing application. The goal of my project is to make the information inside of that…
Adeynack
  • 1,200
  • 11
  • 18
4
votes
0 answers

Jackson filters not working

This worked at one point in Jackson. I want to apply a filter to objects in a Collection. reponse.getOriginalResponse() -> Collection mapper.writer(filterProvider).writeValueAsString(response.getOriginalResponse()); The filter is…
chrislhardin
  • 1,747
  • 1
  • 28
  • 44
4
votes
2 answers

Spring Boot Validation Strategy Before Deserialization

I am using spring boot to run an API. I want to validate the user request parameters before deserialization to prevent jackson from throwing deserialization exceptions. My thinking is it's better to validate without exception handling but if you…
4
votes
3 answers

Jackson mapper expands LocalDate

We have a DTO defined with a LocalDate: @JsonProperty("dob") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") private LocalDate dob; We have code with an ObjectMapper defined as follows: private static final ObjectMapper…
tjholmes66
  • 1,850
  • 4
  • 37
  • 73
4
votes
2 answers

Many to Many relationships using Spring Boot, Jackson and Hibernate

I'm working on a rest project using Spring Boot and Hibernate and am currently trying to figure out how to handle my json-serialization. The schema shown in the ERD above is mapped by Hibernate and works fine. The problem arises when I make a get…
Karim Stekelenburg
  • 633
  • 12
  • 26
4
votes
1 answer

Configure JSON output in Spring JMS messages

What I would like In a Spring Boot 1.5.2 project, I'm sending JSON messages to some JMS (ActiveMQ) queues/topics via JmsTemplate#convertAndSend. I use Java 8 with some instances of LocalDate and LocalDateTime. I would like to change the JSON output…
schweerelos
  • 2,189
  • 2
  • 17
  • 25
4
votes
2 answers

how to apply spring message convertors based on condition?

I have a controller whose response is camelCase json value. Now we are re-writing the code with new version and the response required is in snake_case. I have added a message converter and modified object mapper to…
Pramod
  • 787
  • 4
  • 19