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

Check which jackson library is being used

I need to run a test over a JEE application using com.fasterxml.jackson.core library to determine which version of jackson API has been loaded in memory. I took a look at its API but I couldn't find so far any static class.method returning an…
Carla
  • 3,064
  • 8
  • 36
  • 65
7
votes
2 answers

Spring boot + Jackson + LocalDateTime: Date not parsed correctly

I have a LocalDateTime property in my entity class, but when it's serialized, I don't see the expected format. This is the class: public class MyEntity { private Integer id; @JsonFormat(shape = JsonFormat.Shape.STRING, pattern =…
damian
  • 4,024
  • 5
  • 35
  • 53
7
votes
1 answer

How to modify the object mapper that Spring Cloud AWS uses to deserialize SQS messages?

I need to modify the Jackson2 object mapper that Spring Cloud AWS uses when it deserializes JSON and register a JavaTime module with it. This is because the SQS payload contains an instance of the Java Instant class which has to be deserialized…
teuber789
  • 1,527
  • 16
  • 28
7
votes
2 answers

JSON: @Transient field not seralizing

I have a domain class Loan.java with a field which is not persisted: @JsonInclude() @Transient private LoanRating loanRating; /* (Public) Getters and setters for that field are available as well */ However, the field does not get serialized - I…
dave0688
  • 5,372
  • 7
  • 33
  • 64
7
votes
2 answers

Can't set ProblemHandler to ObjectMapper in Spring Boot

I tried to add custom problem handler to object mapper with Jackson2ObjectMapperBuilderCustomizer: @Bean public Jackson2ObjectMapperBuilderCustomizer customizer() { return new Jackson2ObjectMapperBuilderCustomizer() { @Override …
DamienMiheev
  • 998
  • 8
  • 31
7
votes
1 answer

Change JsonProperty (Access.WRITE_ONLY) programmatically

My Java objects have some fields that are annotated write only because they should not be send over a REST interface to the users. @JsonProperty(access = Access.WRITE_ONLY) private List integerList; Now I am trying to implement an…
Codehai
  • 524
  • 1
  • 7
  • 27
7
votes
1 answer

Should you use @NotNull and @JsonProperty(required) in the same object

So I'm looking at adding constraints to my json views. I have class similar to this one public class Person { @JsonProperty(required = true) @NotNull @Size(max = 50) private String name; } Should I keep both @JsonProperty(required =…
shammancer
  • 397
  • 2
  • 4
  • 8
7
votes
1 answer

Wildcards and query semantics in JsonPointer with Jackson

Jackson provides JsonPointer. However, I want to do something like that what https://github.com/json-path/JsonPath can provide. How do I describe this in JsonPointer?: $.store.book[?(@.price < 10)] somethink like: JsonPointer p =…
nimo23
  • 5,170
  • 10
  • 46
  • 75
7
votes
0 answers

Intercept Deserialization in Jackson

I want to hook into Jackson's deserialization to optionally deserialize a different JSON document than the one provided. That seems like a really weird use case so let me explain. I am using the Amazon SQS Extended client to put messages that are…
Eddie
  • 919
  • 2
  • 9
  • 21
7
votes
1 answer

ISO8601 with milliseconds in json using Jackson

import com.fasterxml.jackson.databind.util.ISO8601DateFormat; objectMapper.setDateFormat(new ISO8601DateFormat()); Nice but this ignores milliseconds, how can I get them in the dates without using the non-thread-safe…
Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
7
votes
2 answers

spark 2.1.1 : Parsed JSON values do not match with class constructor

I've a strange problem with spark 2.1.1 and json4s.jackson. I upgraded my streaming project from spark 1.5.1. Now when I execute code in IDE everything works fine. But after assembly and code standalone execution with spark-submit I got the…
Toren
  • 6,648
  • 12
  • 41
  • 62
7
votes
6 answers

Send empty body in POST request in Retrofit

My api expects an empty json body ({ }) when making post requests. How do I set this up in Retrofit and Jackson? I tried passing null, and empty string, and "{}" but could not get this to work. @POST(my/url) Call createPostRequest(@Body…
fwind
  • 1,274
  • 4
  • 15
  • 32
7
votes
3 answers

Jackson: deserialize epoch to LocalDate

I have following JSON: { "id" : "1", "birthday" : 401280850089 } And POJO class: public class FbProfile { long id; @JsonDeserialize(using = LocalDateDeserializer.class) LocalDate birthday; } I am using Jackson to do…
kpater87
  • 1,190
  • 12
  • 31
7
votes
2 answers

Post a JSON Array into Spring Boot RestController

I am posting something like this: { "stuff": [ { "thingId": 1, "thingNumber": "abc", "countryCode": "ZA" }, { "thingId": 2, "thingNumber": "xyz", "countryCode": "US" } ] } I can retrieve the…
orrymr
  • 2,264
  • 4
  • 21
  • 29
7
votes
1 answer

Treating "N/A" value as null with Jackson

I am getting data from an external JSON API and parsing the result with Jackson. Unfortunately, that API returns all fields as String and those are filled with "N/A" when data is unavailable. I would like to replace those fields with null,…
Chop
  • 4,267
  • 5
  • 26
  • 58