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
6
votes
1 answer

Using Jackson to add XML attributes to manually-built node-tree

I'm trying to set up code to create a node tree using Jackson which can then be used to write either JSON or XML. I've created the node tree manually like so: XmlMapper nodeMapper = new XmlMapper(); ObjectNode rootNode =…
Alexander
  • 261
  • 4
  • 18
6
votes
1 answer

Jackson JSON not serializing Joda DateTime correctly

I have a Joda DateTime in an Order class: public class Order { private DateTime creationTime; ... } I have initialized my mapper as follows: mapper.configure( SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); When I…
Naresh
  • 23,937
  • 33
  • 132
  • 204
6
votes
2 answers

Jackson-CSV schema for array

I have CSV file which I need to parse. The schema for this file is following: name, contacts - where contacts are many strings for each person where the number of this contact columns is not regular. For example: john, john@wick.com, 123 123…
6
votes
2 answers

Jackson annotation to convert BigDecimal value and set scale to 2

I have POJO like where I have a BigDecimal field: public class Foo implements Serializable { private BigDecimal amount; } I want to have the BigDecimal value up to 2 decimal place only. Is there any annotation exist using which I can directly…
6
votes
1 answer

How to disable Jackson from deserializing an Instant from epoch millis?

I am developing an API using Spring Boot and am using Jackson for payload (de)serialization. I want to deserialize an ISO-8601 formatted datetime into a java.time.Instant, but do not want to support deserializing from epoch time in milliseconds or…
6
votes
0 answers

Jackson CSV deserialization ignoring header order

I'm trying to deserialize a csv(tsv) file into an immutable POJO. Jackson is assigning values to the wrong fields (it's ignoring the annotated column header name) The class fields are written in the same order as found in the file. Do I really have…
sikidhart
  • 401
  • 4
  • 16
6
votes
0 answers

Why does @EnableWebMvc break the JSON deserialization?

In my sample application I have a simple @RestController controller: package app.springtest.api.book; import app.springtest.service.BookService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import…
Michal Krasny
  • 5,434
  • 7
  • 36
  • 64
6
votes
4 answers

How do I enable strict validation of JSON / Jackson @RequestBody in Spring Boot REST API?

How do I throw an error if extra parameters are specified in the JSON request? For example, "xxx" is not a valid parameter or in the @RequestBody object. $ curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d…
Chloe
  • 25,162
  • 40
  • 190
  • 357
6
votes
3 answers

How to use dynamic property names for a Json object

How can we make the JSON property name dynamic. For example public class Value { @JsonProperty(value = "value") private String val; public void setVal(String val) { this.val = val; } public String getVal() { …
Spartan
  • 339
  • 1
  • 3
  • 14
6
votes
2 answers

jackson-dataformat-csv: Mapping number value without POJO

I'm trying to parse a CSV file using jackson-dataformat-csv and I want to map the numeric column to the Number java type. CsvSchema schema = CsvSchema.builder().setUseHeader(true) .addColumn("firstName", CsvSchema.ColumnType.STRING) …
Igor Luzhanov
  • 780
  • 1
  • 7
  • 14
6
votes
1 answer

Problem with deserialization of LocalDateTime in Junit test

I have problems LocalDateTime deserialization in Junit test. I have simple REST API which returns some DTO object. When I call my endpoint there is no problem with response - it is correct. Then I try to write unit test, obtain MvcResult and with…
ketrab321
  • 541
  • 2
  • 12
  • 22
6
votes
1 answer

How to deserialize the following json using Jackson

I have the following json: { "id":"myid", "fields":{ "body":"text body" } } which I want to deserialize into the following Java class: class TestItem { private String id; private String body; public String getId() { return…
Rupert Bates
  • 3,041
  • 27
  • 20
6
votes
2 answers

Could not find artifact Jackson-modules-java8:jar

I use open-jdk-10. mvn clean install Could not find artifact com.fasterxml.jackson.module:jackson-modules-java8:jar:2.9.8 in" central"
Yan Khonski
  • 12,225
  • 15
  • 76
  • 114
6
votes
2 answers

Lombok @NonNull null check enforcement not working with Jackson deserialization

I have a simple case where I want to enforce null check on values found in JSON string when converting the JSON string to POJO using Jackson (2.8) and Lombok (latest version) in Java8. But it looks like @NonNull doesn't throw exception when the pojo…
amulllb
  • 3,036
  • 7
  • 50
  • 87
6
votes
6 answers

Spring Boot fails to return JSON for a object but not for list of objects

I am developing my first Spring Boot application and i ran into a weird problem. The configuration is very basic:
Mats Andersson
  • 397
  • 2
  • 7
  • 21