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
8
votes
1 answer

What is the replacement class for SerializerBase in FasterXML Jackson 2?

I am upgrading to Jackson 2. I have many custom serializers extending SerializerBase (org.codehaus.jackson.map.ser.std.SerializerBase). What's the new equivalent class in Jackson 2
mohamed.ibrahim
  • 413
  • 3
  • 8
8
votes
3 answers

Jackson CSV missing columns

I'm using Jackson CSV to parse a CSV file into POJOs. My issue is that if a row in the CSV has too few columns, the parser doesn't complain and just sets the rest of the fields to null. Parsing code: CsvMapper csvMapper = new CsvMapper(); …
rewolf
  • 5,561
  • 4
  • 40
  • 51
8
votes
2 answers

Unable to resolve any beans for Types [org.glassfish.jersey.message.filtering.spi.ObjectProvider]

trying to move from Moxy to Jackson json media provider for my Jersey web service and found couple of issues which I can't resolve so far: first of all moxy was working fine for the same piece of code, but because we are using jackson everywhere in…
Fedor Skrynnikov
  • 5,521
  • 4
  • 28
  • 32
8
votes
2 answers

Is @JsonTypeResolver the only option for resolving using multiple properties?

I have incoming JSON data in the following format { "header": { "schema_id": { "namespace": "omh", "name": "physical-activity", }, }, "body": { "activity_name": "walking", …
Emerson Farrugia
  • 11,153
  • 5
  • 43
  • 51
8
votes
2 answers

Parsing a Json array using Play Framework and Java

I have the following Json structure: { "name": "John", "surname": "Doe", "languages": [ {"language": "english", "level": "3"}, {"language": "french", "level": "1"} ] } I am using the Play Framework to parse Json data from a…
jbrulmans
  • 975
  • 1
  • 11
  • 32
8
votes
2 answers

Spring Boot ignore ObjectMapper module

In application context I have registered an ObjectMapper module: @Bean public SimpleModule jsr310Module() { final SimpleModule module = new SimpleModule(); module.addSerializer(new LocalDateSerializer()); …
rascio
  • 8,968
  • 19
  • 68
  • 108
8
votes
2 answers

How to have Jackson use a method to serialize a class to JSON?

Let's say I have the following classes: public class MyClass { private Test t; public MyClass() { t = new Test(50); } } public class Test { private int test; public Test(int test) { this.test = test; } …
pacoverflow
  • 3,726
  • 11
  • 41
  • 71
8
votes
3 answers

Exception in thread "main" javax.ws.rs.NotAcceptableException: HTTP 406 Not Acceptable

I get the following exception when I execute the REST Client : InboundJaxrsResponse{ClientResponse{method=GET, uri=http://localhost:8080/com.dcr.jersey.first/webapi/todo, status=406, reason=Not Acceptable}} Exception in thread "main"…
Alferd Nobel
  • 3,185
  • 2
  • 30
  • 35
8
votes
2 answers

How to configure Jackson deserializer for nested entites with Spring Boot

Consider the following entities: package br.com.investors.domain.endereco; import com.google.common.base.Objects; import com.google.common.base.Strings; import com.google.common.collect.ComparisonChain; import…
8
votes
2 answers

How can I retain the type property when deserializing with Jackson's @JsonTypeInfo?

I have a setup like this: @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "dishName", defaultImpl = Food.class) @JsonSubTypes(value = { @Type(name = "fries", value = Fries.class), @Type(name =…
Ole
  • 402
  • 5
  • 9
8
votes
1 answer

JsonView - define Default View

I am working on a Spring boot (MVC, JPA) application and it is required to return different attributes on different requests. I found the @JsonView annotation and it seems to work. But do I need to annotate every attribute with a basic…
KenavR
  • 3,769
  • 9
  • 37
  • 47
8
votes
2 answers

Jackson 2.0 ignore all properties on a class

I need the opposite of @JsonIgnore, I need to tell Jackson to ignore all properties on an object except the the ones I annotate. I don't accidentally want someone adding a property and forget adding a @JsonIgnore and then I expose it where I don't…
chrislhardin
  • 1,747
  • 1
  • 28
  • 44
8
votes
1 answer

Read empty YAML file

For a config file format I'd like to use YAML and Jackson to read it. So I have a POJO class Configuration with a few properties and simply read a respective object directly from the file via ObjectMapper.readValue(). In principle that works fine,…
user686249
  • 669
  • 6
  • 17
8
votes
1 answer

Bug in Oracle's JDK zip filesystem, how do you write an SSCCE to reproduce it?

This bug is present in the latest 1.7 and 1.8 versions of the JDK (7u72, 8u25). Required: jackson-databind 2.5.0. Tested on Linux x86_64 (Ubuntu 14.10 to be precise). Code: public static void main(final String... args) throws IOException { …
fge
  • 119,121
  • 33
  • 254
  • 329
8
votes
7 answers

How to include only certain properties and fields of my object to be serialized by Jackson?

I have a class I need to serialize and it contains a lot of properties and fields, but I only need a small subset to be serialized, not the entire class. I also want to guarantee that I won't inadvertently add fields in the future which would be…
Didier A.
  • 4,609
  • 2
  • 43
  • 45