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

How to make Jersey/Jackson serialize empty list; single element list as an array

Using Jersey and Jackson to create a REST interface, how do I get List fields to be serialized as a list when there are 0 or 1 elements in them. For example: @XmlRootElement(name="foo") public class Foo { @XmlElement public List getBars()…
Brandon DuRette
  • 4,810
  • 5
  • 25
  • 31
6
votes
3 answers

Jackson equivalent for iPhone?

I have used Jackson extensively on the Server side to convert from POJOs to JSON and was wondering if there is a similar library for Objective C/iPhone SDK and vice versa. Objective C does provide reflection so it should be possible to make…
Usman Ismail
  • 17,999
  • 14
  • 83
  • 165
6
votes
1 answer

json parse performance between jackson and gson

After searched in google, found that jackson has better performance than gson, i plan to replace gson with jackson in my project, but i got a diffrent result when run test code. private static final Type PHOTOLINKS_TYPE_GSON = new…
situch
  • 103
  • 1
  • 4
6
votes
4 answers

Java Spring Jackons Date serialization

I'm using Spring MVC and Jackson for JSON de/serialization. But im facing a problem with serializing a date. By default Jackson serialize a date as an epoch. But i want to serialize it as a ISO date (i.e. 06-10-2011 11:00:00). The code below is my…
MystyxMac
  • 1,532
  • 2
  • 14
  • 28
6
votes
0 answers

How does JSON maps to List<> even after Type Erasure in Java

I was working with JSONs to send a list of objects to a controller in Spring. My controller method is this: @PostMapping("/fun") public String fun(List users){ for(User user : users){ System.out.println(user); } return…
6
votes
1 answer

Can Jackson be used to update a POJO?

The most generic way to convert from JSON to Java objects is to capture the JSON as a Map. From this (or directly) I can convert to a POJO easily: User user = objectMapper.convertValue(jsonMap, User.class); Any User fields that were…
markvgti
  • 4,321
  • 7
  • 40
  • 62
6
votes
3 answers

Binding the nested json to @RequestBody object using Jackson converter

I have two classes public class Parent { private String name; private int age; private ArrayList children = new ArrayList(); //Setters and getter to follow.. } public Class Child { private String name; private…
user845730
  • 93
  • 1
  • 1
  • 6
6
votes
0 answers

Jackson Object Mapper - "Missing type id " on concrete class deserialization without explicit type info property

I have the following object structure: @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "@type") @JsonSubTypes({ @JsonSubTypes.Type(value = Dog.class, name = "dog") }) interface Animal { String name = null; } @JsonTypeName("dog") class…
avs099
  • 10,937
  • 6
  • 60
  • 110
6
votes
1 answer

Is it possible to register Controller specific ObjectMapper in SpringBoot

We have a usecase where the JSON returned by the endpoint has to be serialized differently based on the endpoint. Is it possible to register two separate ObjectMapper beans and specify which one to use for a specific controller? For example, if I…
RKodakandla
  • 3,318
  • 13
  • 59
  • 79
6
votes
4 answers

Jackson ObjectWriter only writes first entry from stream

I want to create a Spring Boot controller which creates a CSV file using data from a stream. I use Jackson CSV (jackson-dataformat-csv 2.12.1) to write the data stream from the DB to a StreamingResponseBody. To keep it simple, I replaced the actual…
Peter
  • 1,679
  • 2
  • 31
  • 60
6
votes
2 answers

How can I deserialize a nested wrapped String in Jackson?

I have a JSON string that contains a nested and wrapped JSON string. I'd like to deserialize this using Jackson but I'm unsure how. Here's a sample bean: @JsonIgnoreProperties(ignoreUnknown = true) public class SomePerson { public final String…
Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382
6
votes
1 answer

Jackson JSON to Java mapping for same attrubute with different data type

I have a JSON object which I don't have control of and want to map it to a Java object which is pre-created. There is one attribute in the JSON object which can be a URL or it could be a JSONArray. Class SomeClass { private URL items; …
user788052
  • 143
  • 2
  • 8
6
votes
3 answers

Throw error if strings are not double quoted while using jackson objectmapper deserialization

I have a JSON: { "stringField" : 1234, "booleanField": true, "numberField": 1200.00 } I use object mapper to deserialize the json into:- @Data class SomeClass { String stringField; boolean booleanField; float…
Jerald Baker
  • 1,121
  • 1
  • 12
  • 48
6
votes
3 answers

Using Jackson with immutable AWS V2 DDB AttributeValue with private Builder?

I'm trying to serialize/deserialize the DynamoDB V2 AttributeValue class using Jackson. It is setup as an immutable class with a Builder and the builder has a private constructor. In order to create a builder, you need to call…
Matt Klein
  • 7,856
  • 6
  • 45
  • 46
6
votes
1 answer

Deserializing JSON with special characters into a string

I'm trying to parse a json file that looks like this { "foo": "v2", "bar": [ "abc/bcf.xyz", "abc/fgh.xyz" ] } The code I have is currently this: Config.java private static final ObjectMapper…
LunaLove
  • 91
  • 1
  • 6