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
283
votes
19 answers

Jackson enum Serializing and DeSerializer

I'm using JAVA 1.6 and Jackson 1.9.9 I've got an enum public enum Event { FORGOT_PASSWORD("forgot password"); private final String value; private Event(final String description) { this.value = description; } …
pookieman
  • 2,981
  • 2
  • 14
  • 8
278
votes
9 answers

When is the @JsonProperty property used and what is it used for?

This bean 'State' : public class State { private boolean isSet; @JsonProperty("isSet") public boolean isSet() { return isSet; } @JsonProperty("isSet") public void setSet(boolean isSet) { this.isSet =…
blue-sky
  • 51,962
  • 152
  • 427
  • 752
276
votes
9 answers

Converting Java objects to JSON with Jackson

I want my JSON to look like this: { "information": [{ "timestamp": "xxxx", "feature": "xxxx", "ean": 1234, "data": "xxxx" }, { "timestamp": "yyy", "feature": "yyy", "ean": 12345, …
JustTheAverageGirl
  • 2,973
  • 4
  • 17
  • 18
267
votes
6 answers

How to parse a JSON string into JsonNode in Jackson?

It should be so simple, but I just cannot find it after being trying for an hour. I need to get a JSON string, for example, {"k1":v1,"k2":v2}, parsed as a JsonNode. JsonFactory factory = new JsonFactory(); JsonParser jp =…
fadmaa
  • 3,067
  • 3
  • 18
  • 14
245
votes
11 answers

How to convert a JSON string to a Map with Jackson JSON

I'm trying to do something like this but it doesn't work: Map propertyMap = new HashMap(); propertyMap = JacksonUtils.fromJSON(properties, Map.class); But the IDE says: Unchecked assignment Map to…
adamJLev
  • 13,713
  • 11
  • 60
  • 65
239
votes
10 answers

Jackson - Deserialize using generic class

I have a json string, which I should deSerialize to the following class class Data { int found; Class hits } How do I do it? This is the usual way mapper.readValue(jsonString, Data.class); But how do I mention what T stands for?
gnjago
  • 3,391
  • 5
  • 19
  • 17
229
votes
9 answers

How to specify jackson to only use fields - preferably globally

Default jackon behaviour seems to use both properties (getters and setters) and fields to serialize and deserialize to json. I would like to use the fields as the canonical source of serialization config and thus don't want jackson to look at…
Michael Wiles
  • 20,902
  • 18
  • 71
  • 101
226
votes
17 answers

Java 8 LocalDate Jackson format

For java.util.Date when I do @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy") private Date dateOfBirth; then in JSON request when I send { {"dateOfBirth":"01/01/2000"} } it works. How should I do this for Java 8's…
JAB
  • 3,546
  • 9
  • 36
  • 39
215
votes
6 answers

Convert JsonNode into POJO

This may seem a little unusual, but I am looking for an efficient way to transform/map a JsonNode into a POJO. I store some of my Model's information in json files and I have to support a couple of version of my model. What I do is load the json…
Alexandre
  • 4,382
  • 2
  • 23
  • 33
213
votes
11 answers

Jackson overcoming underscores in favor of camel-case

I retrieve a JSON string from internet; like most JSON I've seen it includes long keys that are separated by underscores. Essentially, my goal is to deserialize JSON into java-objects, but I don't use underscores in java-code. For instance, I might…
user1384991
  • 2,559
  • 3
  • 17
  • 20
212
votes
4 answers

How to change a field name in JSON using Jackson

I'm using jackson to convert an object of mine to json. The object has 2 fields: @Entity public class City { @id Long id; String name; public String getName() { return name; } public void setName(String name){ this.name = name; } …
Ali
  • 12,354
  • 9
  • 54
  • 83
210
votes
14 answers

Different names of JSON property during serialization and deserialization

Is it possible: to have one field in class, but different names for it during serialization/deserialization in Jackson library? For example, I have class "Coordiantes". class Coordinates{ int red; } For deserialization from JSON want to have…
kiRach
  • 2,355
  • 2
  • 15
  • 12
210
votes
11 answers

Convert JSON String to Pretty Print JSON output using Jackson

This is the JSON string I…
arsenal
  • 23,366
  • 85
  • 225
  • 331
207
votes
1 answer

Convert Java Object to JsonNode in Jackson

Is it possible to directly convert a Java Object to an JsonNode-Object? The only way I found to solve this is to convert the Java Object to String and then to JsonNode: ObjectMapper mapper = new ObjectMapper(); String json =…
Max Schmidt
  • 7,377
  • 5
  • 23
  • 29
200
votes
10 answers

Date format Mapping to JSON Jackson

I have a Date format coming from API like this: "start_time": "2015-10-1 3:00 PM GMT+1:00" Which is YYYY-DD-MM HH:MM am/pm GMT timestamp. I am mapping this value to a Date variable in POJO. Obviously, its showing conversion error. I would like to…
Kevin Rave
  • 13,876
  • 35
  • 109
  • 173