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
87
votes
6 answers

Is there a jackson datatype module for JDK8 java.time?

I'm looking for a module for the new JDK8 java.time classes. I have looked through the FasterXML GitHub Project Listing and presently found none. As I understand Jackson is still being compiled against JDK6 so can not use these classes directly and…
Brett Ryan
  • 26,937
  • 30
  • 128
  • 163
85
votes
7 answers

Ignore missing properties during Jackson JSON deserialization in Java

In the example class Person { String name; int age; } If the JSON object has a missing property 'age', { "name": "John" } Person person = objectMapper.readValue(jsonFileReader, Person.class); it throws a JsonMappingException saying it…
user379151
  • 1,289
  • 1
  • 16
  • 25
84
votes
10 answers

How to convert JSON string into List of Java object?

This is my JSON Array :- [ { "firstName" : "abc", "lastName" : "xyz" }, { "firstName" : "pqr", "lastName" : "str" } ] I have this in my String object. Now I want to convert it into Java object…
Nitesh
  • 1,477
  • 5
  • 23
  • 34
84
votes
11 answers

java.lang.ClassNotFoundException: com.fasterxml.jackson.annotation.JsonInclude$Value

I am trying to convert my json string to java object and I am getting error Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/annotation/JsonInclude$Value at…
user327126
  • 965
  • 3
  • 11
  • 22
84
votes
12 answers

Using Spring RestTemplate in generic method with generic parameter

To use generic types with Spring RestTemplate we need to use ParameterizedTypeReference (Unable to get a generic ResponseEntity where T is a generic class "SomeClass") Suppose I have some class public class MyClass { int…
Artyom Kozhemiakin
  • 1,432
  • 1
  • 13
  • 13
83
votes
12 answers

Jackson: How to add custom property to the JSON without modifying the POJO

I am developing a REST interface for my app using Jackson to serialize my POJO domain objects to JSON representation. I want to customize the serialization for some types to add additional properties to the JSON representation that do not exist in…
Alex Vayda
  • 6,154
  • 5
  • 34
  • 50
82
votes
1 answer

Convert JsonNode object to Map

I have a C# program that sends me a json object. I'm making a Java Play website to capture the POST data. I get the correct data as a JsonNode object but need to convert it into a Map. I'm using com.fasterxml.jackson.databind.JsonNode Here is where…
visc
  • 4,794
  • 6
  • 32
  • 58
82
votes
2 answers

how to create insert new nodes in JsonNode?

I have a new JsonNode that I created JsonNode jNode = new ObjectCodec().createObjectNode(); with this node, how do I then add key value pairs within so that I can construct this new node with the new values? What I read in…
Dexter Cato
  • 1,091
  • 2
  • 10
  • 11
81
votes
4 answers

JSON Jackson parse different keys into same field

I have a POJO which has a field: public class Media { private Asset asset; } Everything works perfectly when parsing a json response into this asset POJO. but however there is a slight difference with the key this asset comes with. It can either…
DArkO
  • 15,880
  • 12
  • 60
  • 88
80
votes
4 answers

Cannot deserialize instance of object out of START_ARRAY token in Spring Webservice

I'm currently having trouble connecting to my webservice on android. I use jackson-core/databind/annotation-2.2.4 and Spring RESTWebService. If I access the URL from the browser I can see the JSON response: (server return List\Shop\ looks…
Daram
  • 803
  • 1
  • 6
  • 7
80
votes
4 answers

How do I correctly reuse Jackson ObjectMapper?

I am happy with how the ObjectMapper works and general use within my application. What I would like to understand is the best way to implement the ObjectMapper to ensure it is re-used and I'm not creating unnecessary instances within my…
nickebbitt
  • 1,711
  • 1
  • 13
  • 13
78
votes
3 answers

What is the difference between ObjectNode and JsonNode in Jackson?

According to the documetation of JsonNode: Most mutators, however, need to be accessed through specific sub-classes (such as ObjectNode and ArrayNode). However I am still confused since some stackoverflow answers seem to use them quite…
THIS USER NEEDS HELP
  • 3,136
  • 4
  • 30
  • 55
78
votes
8 answers

How to distinguish between null and not provided values for partial updates in Spring Rest Controller

I'm trying to distinguish between null values and not provided values when partially updating an entity with PUT request method in Spring Rest Controller. Consider the following entity, as an example: @Entity private class Person { @Id …
Danilo Cianciulli
  • 875
  • 1
  • 7
  • 9
77
votes
6 answers

Jackson: What happens if a property is missing?

What happens if I annotate a constructor parameter using @JsonProperty but the Json doesn't specify that property. What value does the constructor get? How do I differentiate between a property having a null value versus a property that is not…
Gili
  • 86,244
  • 97
  • 390
  • 689
77
votes
7 answers

How to set format of string for java.time.Instant using objectMapper?

I have an entity with java.time.Instant for created data field: @Getter @Setter @AllArgsConstructor @NoArgsConstructor @EqualsAndHashCode public class Item { private String id; private String url; private Instant createdDate; } I am…
Uladzislau Kaminski
  • 2,113
  • 2
  • 14
  • 33