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

Remove xsi:type information from xml/json JAXB?

I am using JAXB to convert my domain-model to XML and JSON representations. I have Student pojo to convert to XMl/JSON. It has an content property which can be of any data type. Schema definition for it:
Siddharth Trikha
  • 2,648
  • 8
  • 57
  • 101
8
votes
2 answers

How to read single JSON field with Jackson

I have a fairly large JSON response in which I'm interested in single field - status: { "title": "Some title", "status": "pending", "data": { ... }, "meta": { ... } } All I need to do is read the status value of the JSON…
ddinchev
  • 33,683
  • 28
  • 88
  • 133
8
votes
2 answers

Jackson deserializer for generic type

I need to write a custom deserializer for a class with generics. I couldn't find a way to do this, however I cannot imagine I'm the only one with this problem. As far as I've thought through it, there would be two ways to implement this, yet none of…
nsommer
  • 283
  • 1
  • 5
  • 14
8
votes
1 answer

Wanting to get Enum Value instead of name in JSON

I've got the following enum: public enum NotificationType { Store("S"), Employee("E"), Department("D"), All("A"); public String value; NotificationType(String value) { this.value = value; } @Override …
Gregg
  • 34,973
  • 19
  • 109
  • 214
8
votes
1 answer

What is the difference between a property with @JsonIgnore and one with no annotation?

Consider the following class: private static class Widget { @JsonProperty private String id = "ID"; @JsonIgnore private String jsonIgnored = "JSON_IGNORED"; private String noAnnotation = "NO_ANNOTATION"; } If I serialize this…
mattalxndr
  • 9,143
  • 8
  • 56
  • 87
8
votes
1 answer

Deserializing attributes of same name but different types in Jackson?

I have a REST API which returns a JSON response as: { "channel" : "JHBHS" } and sometimes it returns: { "channel": { "id": 12321, "name": "Some channel" } } I have a POJO like: public…
Ram Patra
  • 16,266
  • 13
  • 66
  • 81
8
votes
1 answer

@JsonProperty(access = JsonProperty.Access.WRITE_ONLY) not working

While serialization of the class DataType the dbOptions is been ignored but dataType is being printed with its value. Note I need to ignore the these property only during serialization and not deserialization. @JsonTypeInfo(use =…
souravlahoti
  • 716
  • 2
  • 8
  • 29
8
votes
3 answers

Jackson date format issue : java bean to JSON string conversion

I am converting a java bean to JSON string using Jackson 2.7.4 version. In doing so, I am facing date format issue. Java 1.7 version is being used. Bean : public class BaseBean { private java.util.Date fromDate; public Date getFromDate()…
Rahul Mittal
  • 83
  • 1
  • 5
8
votes
1 answer

Deserializing Polymorphic Types with @JsonUnwrapped using Jackson

What I Want to Do I want to use Jackson to deserialize a polymorphic type, using the standard @JsonTypeInfo annotation as follows: @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.EXISTING_PROPERTY, property =…
Zaaier
  • 685
  • 8
  • 22
8
votes
1 answer

Customize Json serializer instead of Jersey's default?

I am using Jersey to implement RESTful webservice. Now the MediaType in which I return data is JSON. @GET @Produces({MediaType.APPLICATION_JSON }) public Response service() { return Response .ok(entity) …
Siddharth Trikha
  • 2,648
  • 8
  • 57
  • 101
8
votes
1 answer

Override @JsonIgnore in a subclass

I have the following abstract class: public abstract class StandardTimeStamp { @Temporal(TemporalType.TIMESTAMP) @Column(nullable = false) @JsonIgnore private Date lastUpdated; @PreUpdate public void generatelastUpdated() { …
Nick Suwyn
  • 501
  • 1
  • 5
  • 21
8
votes
2 answers

Jackson ObjectMapper throwing NullPointerException even with NON_NULL

When the following JSON is used and either "phones" or "emailAddresses" are null, I'm getting a NullPointerException. JSON: { "item": { "messages": { "user.phone.missing": { "type": "warning", "key":…
ev0lution37
  • 1,129
  • 2
  • 14
  • 28
8
votes
2 answers

Jackson Serialize Field to Different Name

I have this JSON to deserialize: { "first-name": "Alpha", "last-name": "Beta", "gender": "m" } I want to serialize it to 2 different formats: [A] { "first-name": "Alpha", "last-name": "Beta", "gender": "m" } [B] { …
shankshera
  • 947
  • 3
  • 20
  • 45
8
votes
2 answers

Convert javax.json.JsonObject to com.fasterxml.jackson.databind.JsonNode

I have a javax.json.JsonObject and want to validate it against a JSON schema. So I've found the com.github.fge.json-schema-validator. But it works only with com.fasterxml.jackson.databind.JsonNode. Is there a way to convert my JsonObject into a…
Maik
  • 331
  • 2
  • 4
  • 12
8
votes
2 answers

How to serialize single-valued @Data object using Jackson without nesting (e.g. {"id":123}, not {"id":{"value":123}})?

I'm planning to use Lombok for creating hundreds of classes that are based on "value object" pattern as follows: @Data public final class SomeId implements Serializable { private final long value; } And I want to use these classes for JSON…
Kohei Nozaki
  • 1,154
  • 1
  • 13
  • 36