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

Why YAMLGenerator dont close stream depends on configuration

When creating objectMapper with yaml factory there are couple of configuration parameters which you can set: ObjectMapper o = new ObjectMapper(new YAMLFactory()); // o.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); //…
hudi
  • 15,555
  • 47
  • 142
  • 246
8
votes
0 answers

Use Swagger/OpenAPI discriminator so that Jackson serializes object correctly

We're having trouble using the OpenAPI 2.0 discriminator in way that makes both the Swagger tools and the Jackson serializer happy. Problem: during serialization Jackson currently generates two JSON properties for the discriminator, one of them…
Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
8
votes
1 answer

Jackson Deserializer has no default(no arg) constructor

First off, I am aware of this question: CustomDeserializer has no default (no arg) constructor I have used the recommended solution, but have still the same problem. When I try to deserialize my json, I still get the error. I want a custom…
Daniel Töws
  • 347
  • 1
  • 5
  • 21
8
votes
2 answers

Jackson polymorphic serialization generates an incorrect class name

When I use Jackson polymorphic serialization, it generates a JSON object with an incorrect fully qualified class name. The code below serializes an XMLGregorianCalendar. The output is: ["java.util.GregorianCalendar",-3600000] I expected the…
8
votes
1 answer

Jackson's SORT_PROPERTIES_ALPHABETICALLY for Map

I use Jackson 2.5.0. I would like to write a method which takes arbitrary JSON-string and sorts every property by key alphabetically with Jackson. Including nested ones. I learned there is a SORT_PROPERTIES_ALPHABETICALLY feature of Jackson's…
Kirill
  • 6,762
  • 4
  • 51
  • 81
8
votes
2 answers

Jackson - Serialize / Deserialize Enums with Integer fields

There is a very similar question here - Jackson: Serialize and deserialize enum values as integers which deals with using Jackson to serialize and deserialize enums whose solution is pretty simple by using @JsonValue annotation. This does not work…
Pavan Kumar
  • 4,182
  • 1
  • 30
  • 45
8
votes
4 answers

Get all the keys in a JSON string JsonNode in java

I have a json string which I need to validate and find any other keys other than in a list is there in the json string. The sample json string is { "required" : true, "requiredMsg" : "Title needed", "choices" : [ "a", "b", "c", "d" ], …
Senchu Thomas
  • 518
  • 3
  • 9
  • 24
8
votes
2 answers

Jackson (de)serialization of Java8 date/time by a JAX-RS client

I'm making a serivce client for a REST endpoint, using a JAX-RS client for the HTTP requests and Jackson to (de)serialize JSON entities. In order to handle JSR-310 (Java8) date/time objects I added the…
Rinke
  • 6,095
  • 4
  • 38
  • 55
8
votes
3 answers

Use jackson annotation JsonUnwrapped on a field with name different from its getter

I have a class like: class Car { private Engine myEngine; @JsonProperty("color") private String myColor; @JsonProperty("maxspeed") private int myMaxspeed; @JsonGetter("color") public String getColor() { …
learner
  • 1,952
  • 7
  • 33
  • 62
8
votes
5 answers

Jackson: get a null reference on deserializing

I'm using spring-mvc for a restful service. By adding the dependency, my rest controllers automatically generate json from my response entities. Dependency jackson = '2.9.0' compile…
user7803334
8
votes
2 answers

Jackson Java to JSON object mapper modifies field's name

Using Jackson to convert a Java object to JSON ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); jsonMessage = mapper.writeValueAsString(object); the result is that the field "participants" (which is…
heeboir
  • 729
  • 1
  • 9
  • 26
8
votes
1 answer

Jackson - Can't deserialize datetime with timezone offset 'unparsed text found at index 23'

My datetime has to come from frontend with timezone offset: 2017-07-04T06:00:00.000+01:00 I cannot deserialize it with Jackson. The error is: Text '2017-07-04T06:00:00.000+01:00' could not be parsed, unparsed text found at index 23; I was trying…
Marek Urbanowicz
  • 12,659
  • 16
  • 62
  • 87
8
votes
3 answers

com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value

@NotNull @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type") @JsonSubTypes(value = {@JsonSubTypes.Type(value = SimpleGrantedAuthority.class)}) private List
Sammy65
  • 627
  • 2
  • 12
  • 28
8
votes
1 answer

jackson-dataformat-csv: cannot serialize LocalDate

When I try to serialize object containing Local date, I get following error: csv generator does not support object values for properties I have JSR-310 module enabled, with WRITE_DATES_AS_TIMESTAMPS and I can convert the same object to JSON…
charlie_pl
  • 2,898
  • 4
  • 25
  • 39
8
votes
1 answer

For Jackson, How to safely share an ObjectMapper ? Is there any immutable ObjectMapper?

Mapper instances are fully thread-safe, there is no need to create a mapper for single use, but mapper's config can be changed. Although ObjectMapper has copy function to duplicate the config for customize based on exists mapper, if I share a…
wener
  • 7,191
  • 6
  • 54
  • 78