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
66
votes
4 answers

How do you globally set Jackson to ignore unknown properties within Spring?

Jackson has annotations for ignoring unknown properties within a class using: @JsonIgnoreProperties(ignoreUnknown = true) It allows you to ignore a specific property using this annotation: @JsonIgnore If you'd like to globally set it you can…
jnrcorp
  • 1,905
  • 1
  • 18
  • 25
66
votes
4 answers

Right way to write JSON deserializer in Spring or extend it

I am trying to write a custom JSON deserializer in Spring. I want to use default serializer for most part of fields and use a custom deserializer for few properties. Is it possible? I am trying this way because, most part of properties are values,…
gc5
  • 9,468
  • 24
  • 90
  • 151
65
votes
4 answers

JsonManagedReference vs JsonBackReference

I would like to know the difference between @JsonManagedReference and @JsonBackReference in Jackson?
ooozguuur
  • 3,396
  • 2
  • 24
  • 42
65
votes
8 answers

Case insensitive JSON to POJO mapping without changing the POJO

Does anyone know how com.fasterxml.jackson.databind.ObjectMapper is able to map JSON properties to POJO properties case insensitive? JSON-String: [{"FIRSTNAME":"John","LASTNAME":"Doe","DATEOFBIRTH":"1980-07-16T18:25:00.000Z"}] POJO-class: public…
Mark Fellner
  • 651
  • 1
  • 5
  • 3
65
votes
6 answers

Jackson JSON field mapping capitalization?

I'm not clear how jackson deals with capitalization in mapping fields. If anyone could help I'd appreciate it.…
shaz
  • 2,317
  • 4
  • 27
  • 37
64
votes
2 answers

Difference between @JsonIgnore and @JsonBackReference, @JsonManagedReference

I know both @JsonIgnore and @JsonManagedReference, @JsonBackReference are used to solve the Infinite recursion (StackOverflowError), what is the difference between these two? Note : These are Jackson annotations.
Kalyan Pradhan
  • 1,415
  • 3
  • 19
  • 34
64
votes
1 answer

Is Jackson's @JsonSubTypes still necessary for polymorphic deserialization?

I am able to serialize and deserialize a class hierarchy where the abstract base class is annotated with @JsonTypeInfo( use = JsonTypeInfo.Id.MINIMAL_CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") but no @JsonSubTypes…
davidbak
  • 5,775
  • 3
  • 34
  • 50
64
votes
7 answers

Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z

I need to convert json to pojo. I Decided to use jackson and have added jackson-core-2.2.0.jar, jackson-databind-2.4.4.jar and jackson-annotations-2.1.2.jar to my project's classpath I created following Main class: import java.io.IOException; import…
jbakirov
  • 936
  • 2
  • 10
  • 15
63
votes
3 answers

Ignore specific field on serialization with Jackson

I'm using the Jackson library. I want to ignore a specific field when serializing/deserializing, so for example: public static class Foo { public String foo = "a"; public String bar = "b"; @JsonIgnore public String foobar =…
Gustavo Muenz
  • 9,278
  • 7
  • 40
  • 42
63
votes
1 answer

What are @JsonTypeInfo and @JsonSubTypes used for in jackson

What are the @JsonTypeInfo and @JsonSubTypes annotations used for in Jackson? public class Lion extends Animal { private String name; @JsonCreator public Lion(@JsonProperty("name") String name) { this.name = name; } public String getName() { …
Harshit
  • 1,174
  • 1
  • 9
  • 24
63
votes
3 answers

Get raw HTTP response with Retrofit

I want to get the raw http response from my API REST. I have tried with this interface: @POST("/login") @FormUrlEncoded Call login(@Field("username") String login, @Field("password") String pass, …
Héctor
  • 24,444
  • 35
  • 132
  • 243
63
votes
1 answer

Jackson JSON Marshall ignore getter

Im using Jackson to convert a POJO into a JSON to store in the DB. However I have a getter that I want to ignore. I have see a lot of info relating to @JsonIgnoreProperties but I can't seem to make any progress with it. I basically want the…
tarka
  • 5,289
  • 10
  • 51
  • 75
63
votes
4 answers

Jackson - best way writes a java list to a json array

I want to use jackson to convert a ArrayList to a JsonArray. Event.java : this is the java bean class with two fields "field1", "field2" mapped as JsonProperty. My goal is: Convert ArrayList list = new ArrayList(); list.add(new…
Shengjie
  • 12,336
  • 29
  • 98
  • 139
62
votes
15 answers

Strange Jackson exception being thrown when serializing Hibernate object

Jackson is throwing a weird exception that I don't know how to fix. I'm using Spring, Hibernate and Jackson. I have already considered that lazy-loading is causing the problem, but I have taken measures to tell Jackson to NOT process various…
egervari
  • 22,372
  • 32
  • 121
  • 175
62
votes
1 answer

Create JSON object using Jackson in Java

I need to create a JSON string as below using Jackson. I know similar question has been answered already here: Creating a json object using jackson But my expected JSON string is a little different from the one in above example. How can I form…
Shashank Shekher
  • 797
  • 1
  • 8
  • 25