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
187
votes
9 answers

Jackson: how to prevent field serialization

I have an entity class with a password field: class User { private String password; //setter, getter.. } I want this field to be skipped during serialization. But it should still be able to deserialize. This is needed, so that the client…
weekens
  • 8,064
  • 6
  • 45
  • 62
181
votes
12 answers

Jackson renames primitive boolean field by removing 'is'

This might be a duplicate. But I cannot find a solution to my Problem. I have a class public class MyResponse implements Serializable { private boolean isSuccess; public boolean isSuccess() { return isSuccess; } public…
iCode
  • 8,892
  • 21
  • 57
  • 91
175
votes
8 answers

Jackson serialization: ignore empty values (or null)

I'm currently using jackson 2.1.4 and I'm having some trouble ignoring fields when I'm converting an object to a JSON string. Here's my class which acts as the object to be converted: public class JsonOperation { public static class Request { …
Shinnyx
  • 2,144
  • 2
  • 14
  • 21
171
votes
14 answers

Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

I'm trying to POST a List of custom objects. My JSON in request body is this: { "collection": [ { "name": "Test order1", "detail": "ahk ks" }, { "name": "Test order2", …
isah
  • 5,221
  • 3
  • 26
  • 36
170
votes
5 answers

Issue with parsing the content from JSON file with Jackson & message- JsonMappingException -Cannot deserialize as out of START_ARRAY token

Given the following .json file: [ { "name" : "New York", "number" : "732921", "center" : [ "latitude" : 38.895111, "longitude" : -77.036667 ] }, { "name" : "San…
JJD
  • 50,076
  • 60
  • 203
  • 339
168
votes
7 answers

How to modify JsonNode in Java?

I need to change a JSON attribute's value in Java, I can get the value properly but I couldn't modify the JSON. here is the code below JsonNode blablas = mapper.readTree(parser).get("blablas"); for (JsonNode jsonNode : blablas) { …
mstfdz
  • 2,616
  • 3
  • 23
  • 27
168
votes
8 answers

Pretty printing JSON from Jackson 2.2's ObjectMapper

Right now I have an instance of org.fasterxml.jackson.databind.ObjectMapper and would like to get a String with pretty JSON. All of the results of my Google searches have come up with Jackson 1.x ways of doing this and I can't seem to find the…
Anthony Atkinson
  • 3,101
  • 3
  • 20
  • 22
162
votes
5 answers

Jackson how to transform JsonNode to ArrayNode without casting?

I am changing my JSON library from org.json to Jackson and I want to migrate the following code: JSONObject datasets = readJSON(new URL(DATASETS)); JSONArray datasetArray = datasets.getJSONArray("datasets"); Now in Jackson I have the…
Konrad Höffner
  • 11,100
  • 16
  • 60
  • 118
159
votes
8 answers

How can I tell jackson to ignore a property for which I don't have control over the source code?

Long story short, one of my entities has a GeometryCollection that throws an exception when you call "getBoundary" (the why of this is another book, for now let's say this is the way it works). Is there a way I can tell Jackson not to include that…
maverick
  • 2,185
  • 2
  • 16
  • 22
156
votes
13 answers

Jackson databind enum case insensitive

How can I deserialize JSON string that contains enum values that are case insensitive? (using Jackson Databind) The JSON string: [{"url": "foo", "type": "json"}] and my Java POJO: public static class Endpoint { public enum DataType { …
tom91136
  • 8,662
  • 12
  • 58
  • 74
155
votes
8 answers

Why when a constructor is annotated with @JsonCreator, its arguments must be annotated with @JsonProperty?

In Jackson, when you annotate a constructor with @JsonCreator, you must annotate its arguments with @JsonProperty. So this constructor public Point(double x, double y) { this.x = x; this.y = y; } becomes this: @JsonCreator public…
Ori Popowski
  • 10,432
  • 15
  • 57
  • 79
151
votes
15 answers

How do I disable fail_on_empty_beans in Jackson?

Using jackson 2.1, how do I disable the fail_on_empty beans that the error message seems to want me to disable? I'm assuming this is just the simplest thing in the world, but hell it is late and I haven't been able to find a simple tutorial or…
bharal
  • 15,461
  • 36
  • 117
  • 195
150
votes
3 answers

Jackson and generic type reference

I want to use jackson json library for a generic method as follows: public MyRequest tester() { TypeReference> typeRef = new TypeReference>(); MyWrapper requestWrapper = (MyWrapper)…
techzen
  • 2,895
  • 2
  • 22
  • 22
150
votes
11 answers

How do I call the default deserializer from a custom deserializer in Jackson

I have a problem in my custom deserializer in Jackson. I want to access the default serializer to populate the object I am deserializing into. After the population I will do some custom things but first I want to deserialize the object with the…
Pablo Jomer
  • 9,870
  • 11
  • 54
  • 102
141
votes
7 answers

How to convert the following json string to java object?

I want to convert the following JSON string to a java object: String jsonString = "{ "libraryname": "My Library", "mymusic": [ { "Artist Name": "Aaron", "Song Name": "Beautiful" }, { "Artist Name": "Britney", …
Rolando
  • 58,640
  • 98
  • 266
  • 407