Questions tagged [jackson]

Jackson is a Java library for handling tasks like reading and writing (parsing / generating) and data binding to/from Java objects. Although primarily used for JSON, Jackson also supports many other data formats such as Avro, CBOR, CSV, Java Properties, Protobuf, Smile, XML and YAML.

Jackson 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. It offers multiple processing modes including "streaming", "data-binding" and "tree model"; of these, latter two builds on streaming processing.

The Jackson homepage is hosted on GitHub, and the project's Wiki is here.

Alternatives

Alternative Java-to-JSON binding solutions with similar APIs include FastJSON, Google Gson, and svenson. Yet more Java-to-JSON libraries are listed at json.org.

Performance

The latest performance benchmarks for these and other JSON serialization and deserialization solutions for Java are available online.

16401 questions
7
votes
1 answer

Spring Boot: Default serialization for java.time.Duration changed from String to Number

We upgraded lately from Spring Boot 2.1.9 to 2.2.1 which caused our tests to fail. Investigation led to the result that the java.time.Duration type is now serialized differently by default. Instead of having the String "PT15M" in the JSON message we…
hecko84
  • 1,224
  • 1
  • 16
  • 29
7
votes
2 answers

Jackson Serialize Instant to Nanosecond Issue

Jackson serialises java.time.Instant with WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS enabled by default. It produces JSON like this { "timestamp":1421261297.356000000 } I wonder if there's a way to get rid of the zeros at the end. I want something…
J Freebird
  • 3,664
  • 7
  • 46
  • 81
7
votes
2 answers

Java InvalidDefinitionException when serializing object with jackson databind

I'm trying to write the following Player object as String using ObjectMapper from Jackson. package models.Game; import models.Game.Enums.SnowballState; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import…
Kev_T
  • 722
  • 2
  • 9
  • 40
7
votes
2 answers

Disable conversion of scalars to strings when deserializing with Jackson

I want to identify numerical values inserted without quotation marks (as strings) in JSON sent through the request body of a POST request: For example, this would be the wrong JSON format as the age field does not contain quotation marks: { …
7
votes
1 answer

Deserialize to String or Object using Jackson

I have an object that sometimes looks like this: { "foo" : "bar", "fuzz" : "bla" } and sometimes looks like this: { "foo" : { "value" : "bar", "baz": "asdf" }, "fuzz" : { "thing" : "bla", "blip" : "asdf" } } these classes would look…
Doug
  • 14,387
  • 17
  • 74
  • 104
7
votes
1 answer

How to custom convert String to enum in @RequestBody?

I want to send a JSON request body where fields can be enum values. These enum values are in camelCase, but the enum values are UPPER_SNAKE_CASE. Kotlin classes: data class CreatePersonDto @JsonCreator constructor ( …
LordSerius
  • 135
  • 1
  • 7
7
votes
1 answer

Polymorphic deserialization in Jackson without annotations

I have a CloudEvent class that uses polymorphic deserialization using Jackson (2.9.0 - last version) like this: @Data @NoArgsConstructor @AllArgsConstructor public class CloudEvent { @NonNull private String eventType; …
Razor
  • 719
  • 8
  • 18
7
votes
2 answers

How to use Jackson to deserialize external Lombok builder class

I have a 3rd party Lombok builder POJO, one that I cannot modify, that I want to serialize using jackson. Notably it does not have a NoArgsConstructor. @Data @Builder public class ExternalClass { private String name; private String data; …
pscl
  • 3,322
  • 25
  • 29
7
votes
1 answer

Jackson Deserializer delegate to next applicable deserializer

I have an external service which I use to query some data. The data will be in one of two formats (first of which is kind of "legacy", but needs to be supported): { "foo": "John Smith" } or { "foo": { "name": "John Smith", …
user900547
7
votes
1 answer

Why kotlin jackson can't deserialize list

I have a function: inline fun parse(result: String): T = mapper.readValue>(result).someValue When I pass a list type, e.g. List, and try to get some item from it, I get the following exception: Exception in…
kolay
  • 73
  • 1
  • 6
7
votes
1 answer

Can not construct instance of java.util.LinkedHashMap: no String-argument constructor/factory

Facing issues while parsing a file and converting into POJO. Below exception I am getting. com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of java.util.LinkedHashMap: no String-argument constructor/factory method to…
user6597131
  • 73
  • 1
  • 1
  • 4
7
votes
1 answer

TypeReference>() { }

Since few days ago I started to work on a webservice project. This project is using Jackson to marshalling and unmarshalling JSON objects. So my question is: Why always I have to put the {} when I am creating an instance of TypeReference? I know the…
Raikish
  • 634
  • 2
  • 6
  • 20
7
votes
4 answers

How to ignore a specific node when parsing XML with Jackson

I want to know if it's possible to ignore one or many nodes when parsing XML using Jackson ML module. I want to be able to parse this XML
Fred
  • 741
  • 2
  • 10
  • 22
7
votes
2 answers

JsonIgnore on Field vs JsonIgnore on getter of a field in Jackson

What is the difference between JsonIgnore on Field vs JsonIgnore on a getter of a field in Jackson?
Sagar
  • 5,315
  • 6
  • 37
  • 66