I have a use case where I am consuming from multiple topics and based on the topic I have to create an object from a String. I have around 25 topics leading to 25 kinds of objects. So, instead of using a bunch of if-else, I want to use a map where the key will be the topic name. So,
Tag: jackson
Java show/hide object fields depending on REST call
Is it possible to config the Item class that depending on the REST call to show and hide specific fields? For example I want to hide colorId (and show categoryId) from User class when calling XmlController and vice versa when calling JsonController. Item class JSON Controller XML Controller Answer I’ve solved it by creating following View: With this config it
How to replace a value of the given key path in dynamic json object using java
I have dynamic JSONs and their key-path, I need to change the values of the Json on received key paths As an example, in have below JSON and key (cars.car1) I need to change the value of cars.car1. as “Benz”. Also Please Note JSON body and its keys will change from time to time. As an example, next time I
How to create Array of Objects using the Jackson Streaming API
I am trying to create a JSON using the Jackson Streaming API. I know how to create an array of elements in JSON using Jackson as we have plenty of examples related to it. But I am a bit confused about how to create an array of Objects using it. Following is the JSON structure that I would like to
Passing arguments to Java class used in @JsonSerialize and @JsonDeserialize
I have a scenario which I am not sure how to google, so I’d open a question myself. If its a duplicate please link it here so I can give that question credit. Anyway, I have a Java Object with fields that I have the following annotations: The business dictates that certain systemDate values in different database have different time
I am trying to convert Xml doc to java obj.Its showing array index out of bounds exception fro the parameter serviceproviders
error Exception in thread “main” java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 0 at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248) at java.base/java.util.Objects.checkIndex(Objects.java:373) at java.base/java.util.ArrayList.get(ArrayList.java:427) at Parser.main(Parser.java:18) Answer The problem is in your ServiceProviders class. There you have modeled the sequence of <ServiceProvider> elements by That means, within <ServiceProviders>…</ServiceProviders> you expect XML input like this instead of simply Of course you
Spring Jackson deserialize object with reference to existing object by Id
I have three entity classes of the following: Shipments Entity: Shipment Details Entity: Product Entity: I am receiving JSONs through a rest API. The problem is I do not know how to deserialize a new Shipment with shipmentDetails that have relationships to already existing objects just by ID. I know you can simply deserialize with the objectmapper, but that requires
Jackson XML deserialization of abstract type results in fields with null values
When trying to deserialize XML to an object that extends an abstract base class, I’m seeing that the list of references contains the expected number of elements, but all the fields on those objects are null. This only happens if I create an XML reader for the abstract class. If I deserialize directly to the concrete implementation all the fields
‘com.google.api.client.json.jackson2.JacksonFactory’ is deprecated. What are my options?
While following the Gmail API java quickstart guide I came across this code snippet: Using it in the editor gave me a warning that it is deprecated. What are my options? Answer Look up the API documentation of class JacksonFactory. It tells you what to do: Deprecated. use com.google.api.client.json.GsonFactory instead Looking into the API documentation of class GsonFactory you see,
Jackson JSON custom class instantiator for third-party class
I am using a third-party POJO class RetryOptions that can only be created using a builder. The builder can only be instantiated using a static method RetryOptions.newBuilder(), or by calling options.toBuilder() on an existing instance. I would like to create custom de/serializers for the third-party POJO (RetryOptions). My first approach was to write the object as a builder, then read