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
140
votes
21 answers

Can't make Jackson and Lombok work together

I am experimenting in combining Jackson and Lombok. Those are my classes: package testelombok; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import…
135
votes
8 answers

How to map a nested value to a property using Jackson annotations?

Let's say I'm making a call to an API that responds with the following JSON for a product: { "id": 123, "name": "The Best Product", "brand": { "id": 234, "name": "ACME Products" } } I'm able to map the product id and name just…
kenske
  • 2,235
  • 2
  • 20
  • 27
128
votes
12 answers

How can I include raw JSON in an object using Jackson?

I am trying to include raw JSON inside a Java object when the object is (de)serialized using Jackson. In order to test this functionality, I wrote the following test: public static class Pojo { public String foo; @JsonRawValue public…
bhilstrom
  • 1,471
  • 2
  • 11
  • 8
128
votes
10 answers

How to serialize Joda DateTime with Jackson JSON processor?

How do I get Jackson to serialize my Joda DateTime object according to a simple pattern (like "dd-MM-yyyy")? I've tried: @JsonSerialize(using=DateTimeSerializer.class) private final DateTime date; I've also tried: ObjectMapper mapper = new…
Haywood Jablomey
  • 1,255
  • 2
  • 9
  • 3
127
votes
11 answers

How do I use a custom Serializer with Jackson?

I have two Java classes that I want to serialize to JSON using Jackson: public class User { public final int id; public final String name; public User(int id, String name) { this.id = id; this.name = name; …
Jonas
  • 121,568
  • 97
  • 310
  • 388
127
votes
23 answers

java.lang.IllegalArgumentException: No converter found for return value of type

With this code @RequestMapping(value = "/bar/foo", method = RequestMethod.GET) public ResponseEntity foo() { Foo model; ... return ResponseEntity.ok(model); } } I get the following…
Marc
  • 16,170
  • 20
  • 76
  • 119
127
votes
1 answer

org.codehaus.jackson versus com.fasterxml.jackson.core

Are org.codehaus.jackson and com.fasterxml.jackson.core related? I have org.codehaus.jackson jackson-all version 1.7.2 and com.fasterxml.jackson.core > jackson-databind version 2.4.3 in my pom.xml. I am not sure if they are redundant and can…
Aniruddh Joshi
  • 1,705
  • 3
  • 12
  • 18
126
votes
7 answers

Deserialize JSON with Jackson into Polymorphic Types - A Complete Example is giving me a compile error

I am attempting to work through a tutorial from Programmer Bruce that is supposed to allow the deserialization of polymorphic JSON. The complete list can be found here Programmer Bruce tutorials (Great stuff btw) I have worked through the first five…
Jon Driscoll
  • 1,263
  • 2
  • 9
  • 4
123
votes
14 answers

How to customise the Jackson JSON mapper implicitly used by Spring Boot?

I'm using Spring Boot (1.2.1), in a similar fashion as in their Building a RESTful Web Service tutorial: @RestController public class EventController { @RequestMapping("/events/all") EventList events() { return…
Jonik
  • 80,077
  • 70
  • 264
  • 372
121
votes
5 answers

Deserialize JSON to ArrayList using Jackson

I have a Java class MyPojo that I am interested in deserializing from JSON. I have configured a special MixIn class, MyPojoDeMixIn, to assist me with the deserialization. MyPojo has only int and String instance variables combined with proper getters…
tacos_tacos_tacos
  • 10,277
  • 11
  • 73
  • 126
121
votes
7 answers

Jackson JSON custom serialization for certain fields

Is there a way using Jackson JSON Processor to do custom field level serialization? For example, I'd like to have the class public class Person { public String name; public int age; public int favoriteNumber; } serialized to the follow…
Steve Kuo
  • 61,876
  • 75
  • 195
  • 257
120
votes
9 answers

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.testing.models.Account

I'm getting below error: java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.testing.models.Account with below code final int expectedId = 1; Test newTest = create(); int expectedResponseCode =…
Passionate Engineer
  • 10,034
  • 26
  • 96
  • 168
117
votes
12 answers

Jackson ObjectMapper - specify serialization order of object properties

I'm implementing a RESTful web service where user has to send a signed verification token along with the request so that I could ensure that the request has not been tampered by a middle man. My current implementation is as follows. Verification…
Lizzy
  • 2,033
  • 3
  • 20
  • 33
117
votes
6 answers

Order of JSON objects using Jackson's ObjectMapper

I'm using ObjectMapper to do my java-json mapping. ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); ow.writeValue(new File( fileName +".json"), jsonObj); this is my java class: public class Relation { private String…
justSaid
  • 1,540
  • 2
  • 12
  • 23
117
votes
11 answers

Setting default values to null fields when mapping with Jackson

I am trying to map some JSON objects to Java objects with Jackson. Some of the fields in the JSON object are mandatory(which I can mark with @NotNull) and some are optional. After the mapping with Jackson, all the fields that are not set in the JSON…
gookman
  • 2,527
  • 2
  • 20
  • 28