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
115
votes
6 answers

JSON parse error: Can not construct instance of java.time.LocalDate: no String-argument constructor/factory method to deserialize from String value

I am new to Spring Data REST project and I am trying to create my first RESTful service. The task is simple, but I am stuck. I want to perform CRUD operations on a user data stored in an embedded database using RESTful API. But I cannot figure out…
zavanton
  • 1,424
  • 2
  • 9
  • 14
113
votes
12 answers

Configuring ObjectMapper in Spring

My goal is to configure the objectMapper in the way that it only serialises element which are annotated with @JsonProperty. In order to do so I followed this explanation which says how to configurate the objectmapper. I included the custom…
Steve Eastwood
  • 1,783
  • 3
  • 16
  • 21
111
votes
6 answers

Jackson + Builder Pattern?

I'd like Jackson to deserialize a class with the following constructor: public Clinic(String name, Address address) Deserializing the first argument is easy. The problem is that Address is defined as: public class Address { private…
Gili
  • 86,244
  • 97
  • 390
  • 689
109
votes
15 answers

No content to map due to end-of-input jackson parser

I am getting this response from the server {"status":"true","msg":"success"} I am trying to parse this json string using Jackson parser library but somehow I am facing mapping-exception stating com.fasterxml.jackson.databind.JsonMappingException:…
Swapnil Kadam
  • 4,075
  • 5
  • 29
  • 35
108
votes
4 answers

How to parse a JSON string to an array using Jackson

I have a String with the following value: [ { "key1": "value11", "key2": "value12" }, { "key1": "value21", "key2": "value22" } ] And the following class: public class SomeClass { private String key1; private String…
mmutilva
  • 18,688
  • 22
  • 59
  • 82
105
votes
10 answers

Cannot construct instance of - Jackson

I am using Jackson and I'm having problems, when I try to deserialize an Object I get the following error: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of net.MyAbstractClass, problem: abstract types…
Danilo M.
  • 1,422
  • 5
  • 17
  • 31
98
votes
6 answers

Casting LinkedHashMap to Complex Object

I've got an application that stores some data in DynamoDB using Jackson to marshall my complex object into a JSON. For example the object I'm marshalling might look like this: private String aString; private List someObjectList; Where…
tarka
  • 5,289
  • 10
  • 51
  • 75
96
votes
7 answers

Serializing enums with Jackson

I have an Enum desrcibed below: public enum OrderType { UNKNOWN(0, "Undefined"), TYPEA(1, "Type A"), TYPEB(2, "Type B"), TYPEC(3, "Type C"); private Integer id; private String name; private WorkOrderType(Integer id, String name) { …
Nofate
  • 2,714
  • 3
  • 32
  • 32
96
votes
4 answers

How to deserialize a class with overloaded constructors using JsonCreator

I am trying to deserialize an instance of this class using Jackson 1.9.10: public class Person { @JsonCreator public Person(@JsonProperty("name") String name, @JsonProperty("age") int age) { // ... person with both name and…
geejay
  • 5,440
  • 8
  • 50
  • 60
95
votes
15 answers

Avoid Jackson serialization on non fetched lazy objects

I have a simple controller that return a User object, this user have a attribute coordinates that have the hibernate property FetchType.LAZY. When I try to get this user, I always have to load all the coordinates to get the user object, otherwise…
r1ckr
  • 5,643
  • 5
  • 20
  • 24
93
votes
8 answers

How do I obtain the Jackson ObjectMapper in use by Spring 4.1?

Spring 4.1 instantiates a Jackson ObjectMapper instance. I have reason to want to @Autowire that instance into one of my controllers: The controller does some minor JSON parsing of its own using Jackson, but the ObjectMapper it uses should be the…
Adam Maass
  • 931
  • 1
  • 6
  • 6
93
votes
10 answers

Spring REST Service: how to configure to remove null objects in json response

I have a spring webservice that returns a json response. I'm using the example given here to create the service: http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/ The format the json is returned in…
mikec
  • 939
  • 1
  • 6
  • 4
92
votes
3 answers

Generics with Spring RESTTemplate

I have a class like that: public class Wrapper { private String message; private T data; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public T getData() { …
kamaci
  • 72,915
  • 69
  • 228
  • 366
92
votes
7 answers

Deserializing an enum with Jackson

I'm trying and failing to deserialize an enum with Jackson 2.5.4, and I don't quite see my case out there. My input strings are camel case, and I want to simply map to standard Enum conventions. @JsonFormat(shape = JsonFormat.Shape.STRING) public…
jwilner
  • 6,348
  • 6
  • 35
  • 47
88
votes
5 answers

How can we configure the internal Jackson mapper when using RestTemplate?

I want to update the SerializationConfig.Feature... properties of the jackson mapper used by Spring RestTemplate, Any idea how I can get to it or where I can/should configure it.
Usman Ismail
  • 17,999
  • 14
  • 83
  • 165