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
76
votes
5 answers

How to deserialize JS date using Jackson?

I'm getting a date string from ExtJS in the format: "2011-04-08T09:00:00" when i try to deserialize this date, it changes the timezone to Indian Standard Time (adds +5:30 to the time) . This is how i'm deserializing the date: SimpleDateFormat…
Varun Achar
  • 14,781
  • 7
  • 57
  • 74
75
votes
2 answers

Jackson - @JsonTypeInfo property is being mapped as null?

Say I have the following JSON: { "id":"decaa828741611e58bcffeff819cdc9f", "statement":"question statement", "exercise_type":"QUESTION" } then, based on the exercise_type field, I want to instantiate different objects instances…
jscherman
  • 5,839
  • 14
  • 46
  • 88
71
votes
3 answers

How to serialize only the ID of a child with Jackson

Is there a built-in way to only serialize the id of a child when using Jackson (fasterxml.jackson 2.1.1)? We want to send an Order via REST which has a Person reference. The person object however is quite complex and we could refresh it on the…
Pete
  • 10,720
  • 25
  • 94
  • 139
70
votes
5 answers

Can not find a (Map) Key deserializer for type [simple type, class ...]

I have a domain object that has a Map: private Map> autoHandling; When I serialize the object, I get this: "autoHandling" : [ "java.util.HashMap", { } ], This Map's key is a custom Object: public…
Mick Knutson
  • 2,297
  • 3
  • 25
  • 48
70
votes
17 answers

Spring Rest POST Json RequestBody Content type not supported

When I try to post new object with post method. RequestBody could not recognize contentType. Spring is already configured and POST could work with others objects, but not this specific one. org.springframework.web.HttpMediaTypeNotSupportedException:…
Thibaut
  • 2,596
  • 2
  • 24
  • 24
69
votes
4 answers

Convert Map to JSON using Jackson

How can I convert a Map to a valid JSON using Jackson? I am doing it using Google's GSON via a Spring Boot REST Post method... Here's the RESTful Web Service: import java.util.Map; import org.springframework.web.bind.annotation.RequestBody; import…
PacificNW_Lover
  • 4,746
  • 31
  • 90
  • 144
69
votes
5 answers

Correct set of dependencies for using Jackson mapper

I am new to Jackson and I was writing some code for practice. I found out that the new version of Jackson library can be found on Fasterxml: Jackson, so I added the below dependencies to my Maven POM-file:
Hossein
  • 40,161
  • 57
  • 141
  • 175
69
votes
5 answers

Can not deserialize instance of java.util.ArrayList out of VALUE_STRING

I have a REST service built with Jersey and deployed in the AppEngine. The REST service implements the verb PUT that consumes an application/json media type. The data binding is performed by Jackson. The verb consumes an enterprise-departments…
Manolo
  • 1,500
  • 1
  • 11
  • 15
68
votes
5 answers

Jackson deserialize ISO8601 formatted date-time into Java8 Instant

I'm trying to deserialize an ISO8601 formatted date into Java8 java.time.Instant using Jackson. I registered JavaTimeModule with the ObjectMapper, and turned off the WRITE_DATES_AS_TIMESTAMPS setting. However, if one tries to deserialize…
Krešimir Nesek
  • 5,302
  • 4
  • 29
  • 56
68
votes
7 answers

Using Jackson ObjectMapper with Java 8 Optional values

I was trying to use Jackson to write a class value to JSON that has Optional as fields: public class Test { Optional field = Optional.of("hello, world!"); public Optional getField() { return field; } public…
asieira
  • 3,513
  • 3
  • 23
  • 23
68
votes
7 answers

Java to Jackson JSON serialization: Money fields

Currently, I'm using Jackson to send out JSON results from my Spring-based web application. The problem I'm having is trying to get all money fields to output with 2 decimal places. I wasn't able to solve this problem using setScale(2), as numbers…
ControlAltDel
  • 33,923
  • 10
  • 53
  • 80
67
votes
7 answers

Why does Jackson 2 not recognize the first capital letter if the leading camel case word is only a single letter long?

I'm using Spring 4 MVC with Jackson 2 for my service. For one of the operations I have a request object that has an attribute where the leading camel case word this is only one letter in length: private String aLogId; This class has the…
Hazok
  • 5,373
  • 4
  • 38
  • 48
67
votes
6 answers

Parsing JSON in Java without knowing JSON format

I am trying to parse JSON strings in Java and find the key-value pairs so that I can determine the approximate structure of the JSON object since object structure of JSON string is unknown. For example, one execution may have a JSON string like…
whyceewhite
  • 6,317
  • 7
  • 43
  • 51
66
votes
7 answers

Usage of Jackson @JsonProperty annotation for kotlin data classes

kotlin 1.2.10 jackson-module-kotlin:2.9.0 I have the following data class in kotlin: data class CurrencyInfo( @JsonProperty("currency_info") var currencyInfo: CurrencyInfoItem? ) @JsonInclude(JsonInclude.Include.NON_NULL) data class…
Mike
  • 725
  • 1
  • 8
  • 11
66
votes
6 answers

How to unit-test Jackson JsonSerializer and JsonDeserializer

I've written custom JsonSerializer and JsonDeserializer for my app. Now I want to write some unit-tests for them. How should a clean test case look like? Are there some clean examples out there? (clean means no dependencies to other frameworks or…
gue
  • 1,099
  • 2
  • 9
  • 18