Questions tagged [jackson2]

Use this tag only for questions specifically related to version 2 of the Jackson library

Jackson version 2 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.

464 questions
3
votes
0 answers

Filter properties similar to JsonFilter during deserialization

I am using Jackson 2 and struggled with dynamic filtering of properties during deserialization. My idea is to load an entity and just read the changes: objectMapper.readerForUpdating(entity).readValue(json) I was trying to use @JsonView, which…
CSchulz
  • 10,882
  • 11
  • 60
  • 114
2
votes
4 answers

how to make java class behave like a normal object and list-of-object at runtime and as per need?

I have a simple class in java like below: class Simple { private String name; private String email; } I want to have behaviour of java.util.List and Simple both according to input data that my program receives. i.e. Case 1:: if my…
axnet
  • 5,146
  • 3
  • 25
  • 45
2
votes
1 answer

Mixin adding defaultImpl in Jackson does not work

I want to use Jackson mixin to provide a default implementation for an abstract type: @JsonTypeInfo( use = Id.NAME, include = As.PROPERTY, property = "type", visible = true, defaultImpl =…
pixel
  • 24,905
  • 36
  • 149
  • 251
2
votes
2 answers

Jackson deserialization using JsonParser distinguish between the direct object and objects within array

I am using the Jackson for the Deseilization of the JSON. The Deseilization works perfectly for a JSON with CustomerDocument. However, I have a new requirement in which I need to find whether provided JSON has CustomerDocument or just Customer. I am…
BATMAN_2008
  • 2,788
  • 3
  • 31
  • 98
2
votes
1 answer

Getting this error No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer

@Entity @Data @JsonIgnoreProperties(ignoreUnknown = true) public class SomeRandomEntity { private String var1; private String var2; private String var3; public JSONObject getJSONObject throws JSONException { JSONObject properties =…
Sarthak Mittal
  • 135
  • 1
  • 2
  • 11
2
votes
1 answer

Remove empty JSON objects from an array in Jackson serialization

I have a List in a Java Pojo class. That list contains some MyChildPojo objects which are not null but can have properties with null values. Example: MyChildPojo obj1 = new MyChildPojo(); MyChildPojo obj2 = new MyChildPojo(); I have added…
2
votes
2 answers

jackson - skip keys with null values while serializing the HashMap object

I'm trying to serialize the Java object with hashmap into json string using jackson object mapper. Below is the class definition of Ext - import com.fasterxml.jackson.annotation.JsonAnyGetter; import…
user51
  • 8,843
  • 21
  • 79
  • 158
2
votes
1 answer

How does jackson @JsonGetter and @JsonSetter work

I am using jackson 2.10.0 (https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core/2.10.0), following is a simple test case The Person class is defined as follows, for the setters, I have used the @JsonSetter annotation, and…
Tom
  • 5,848
  • 12
  • 44
  • 104
2
votes
2 answers

Jackson ObjectMapper not able to recognize @JsonProperty Annotation

I am creating POJO's using jsonschema2pojo-maven-plugin, version 0.4.30. But when I use those pojo's in my code, Jackson ObjectMapper is not able to recognise @JsonProperty annotation. Below is the sample json: { "title": "IP Address", …
Shrikant
  • 155
  • 3
  • 13
2
votes
1 answer

Deserialize Codehaus-Jackson annotated class entity via FasterXML-Jackson?

My application has two modules: an API A and a visualization component V. Some API model classes are annotated via org.codehaus.jackson.annotation (Jackson 1.9.13). In one logic flow, objects based on these models are JSON-serialized and delivered…
Janaka Bandara
  • 1,024
  • 1
  • 12
  • 27
2
votes
4 answers

Jackson - Serialize only Ids of objects in a list attribute of a Java Pojo

I want to optimize the json data to be sent on wire. I have three models in my code. These are Customer, Invoice and Particular. The Customer class @Data public class Customer implements Serializable { private long customerId; private…
Pawan
  • 1,183
  • 16
  • 29
2
votes
1 answer

Passing String value to Jackson Custom Deserializer in Java

I have created a Jackson Custom Deserializer to deserialize a JSON string : public class TestMapper extends StdDeserializer { public TestMapper() { this(null); } public TestMapper(Class vc) { super(vc); } …
apandey
  • 85
  • 1
  • 4
  • 13
2
votes
1 answer

How parse nested escaped json with Jackson?

Consider json: { "name": "myName", "myNestedJson": "{\"key\":\"value\"}" } Should be parsed into classes: public class MyDto { String name; Attributes myNestedJson; } public class Attributes { String key; } Can it be parsed…
Cherry
  • 31,309
  • 66
  • 224
  • 364
2
votes
1 answer

ObjectMapper : How to get the root element in snake case

I am trying to read object and convert into string. But the root element is getting changed from payment_token to PaymentToken. ObjectMapper mapper = new…
Kiran
  • 839
  • 3
  • 15
  • 45
2
votes
2 answers

Java Jackson Serialize List of Abstract Class

Scenario Imagine that I have an abstract class named InfoItem, that each class that inherits from it is a different type of Info Type that is used later to help me with the classification. Each InfoItem have a timestamp as a property (when does this…
Bar Bokovza
  • 169
  • 1
  • 2
  • 12