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

Is it possible to get the original field names of @JsonProperty?

I need to create a map of @JsonProperty Values to Original field names. Is it possible to achieve? My POJO class: public class Contact { @JsonProperty( "first_name" ) @JsonView( ContactViews.CommonFields.class ) private String firstName; …
8
votes
3 answers

Android Studio trouble setting up Jackson Parser on gradle

I'm having trouble adding the Jackson Parser dependency to my project. Currently I'm using these lines of code on my build.gradle: compile 'com.fasterxml.jackson.core:jackson-core:2.7.2' compile…
Igor Morse
  • 657
  • 2
  • 8
  • 20
8
votes
3 answers

How can I get Jackson to deserialize into my own Array implementation

Given my own array implementation MyArray, how can I make it known to Jackson, so that it is able to deserialize from a JSON Array into MyArray? So far I am only getting this exception: com.fasterxml.jackson.databind.JsonMappingException: Can…
tyrondis
  • 3,364
  • 7
  • 32
  • 56
8
votes
1 answer

Jackson @JsonIgnore fields based on spring security roles

In all of my Spring REST Web application, I have a lot of domain objects and DTOs. I need to filter some domain object or DTOs fields based on the spring security roles of the user who makes the request. I want Jackson to filter the output JSON to…
singe3
  • 2,065
  • 4
  • 30
  • 48
8
votes
2 answers

Jackson - Custom TypeId Resolver

I've been using a custom typeId resolver for one of my classes, so far I've been leaning on the annotation support: @JsonTypeInfo( use = JsonTypeInfo.Id.CUSTOM, include = JsonTypeInfo.As.PROPERTY, property =…
Vinicius Carvalho
  • 3,994
  • 4
  • 23
  • 29
8
votes
3 answers

Custom deserialization of List using Jackson

I am trying to write a custom deserializer in order to trim down a big set of data I receive from somewhere else. I return a List of custom objects from the deserializer. My question is, how do I do that, if this is my custom deserializer : public…
D.Razvan
  • 325
  • 1
  • 5
  • 18
8
votes
1 answer

Spring REST returning PDF - Response status 406 (not acceptable)

I read many questions on SO about this type of issue, but all of them recommend using the correct Jackson version. This is my current situation: REST API: @RequestMapping(value = "get/pdf/{id}", headers="Accept=*/*", method = RequestMethod.GET,…
Manu
  • 4,019
  • 8
  • 50
  • 94
8
votes
2 answers

Spark crash while reading json file when linked with aws-java-sdk

Let config.json be a small json file : { "toto": 1 } I made a simple code that read the json file with sc.textFile (because the file can be on S3, local or HDFS, so textFile is convenient) import org.apache.spark.{SparkContext,…
Boris
  • 1,093
  • 2
  • 14
  • 22
8
votes
1 answer

Can't inject multiple ObjectMapper beans in Spring Boot application

I am defining beans using @Bean annotation and trying to wire them using name , but receiving an exception. Complete Example package com.example; import org.springframework.boot.SpringApplication; import…
Punter Vicky
  • 15,954
  • 56
  • 188
  • 315
8
votes
2 answers

How to disable/enable jackson SerializationFeature.WRAP_ROOT_VALUE?

I'm using JSONAPI, so I need to wrap some classes, but not all classes, like: {"users": {"aKey": "aValue"}} // wrapped. {"aKey": "aValue"} // not wrapped. There's a way to disable tis feature dynamically or from the class itself?, I try…
nebiros
  • 717
  • 10
  • 30
8
votes
2 answers

Convert String to Integer using FasterXML Jackson

I'm consuming two JSONs. The first one has the ID as a String. "details": { "id": "316.0" } The other one has the ID as Integer. "details": { "detailId": 316 } Both JSONs are being mapped with FasterXML to two different classes. I want…
Lucas Beier
  • 621
  • 1
  • 7
  • 19
8
votes
3 answers

Why is Jersey ignoring my Jackson annotations?

I'm using Jersey and Jackson to create a simple JSON API. Some of the objects being serialized have custom enum fields. By default, those enums are converted to a string based on the enum vale -- I would like the enums to have slightly more complex…
slifty
  • 13,062
  • 13
  • 71
  • 109
8
votes
5 answers

java8 - absent variable & Optional

I am parsing input JSON. For a field, there are 3 possibilities: the field is absent; the value is set to null; the value is set to something valid. Different behavior is implemented: for an absent value in the JSON, the default value is inserted…
user4444533
8
votes
1 answer

Can I customize Jackson error messages?

I've got a JacksonMappingException that I'm using to produce errors for the user: public Map>> getErrors(JsonMappingException e) { …
Dmitry Minkovsky
  • 36,185
  • 26
  • 116
  • 160
8
votes
2 answers

Get list of unknown fields from Jackson

I have a JSON schema, and a json string that matches the schema, except it might have a few extra fields. Jackson will throw an exception if those fields are there if I don't add…
Tavo
  • 3,087
  • 5
  • 29
  • 44