Jackson deserialize based on type

Annotations-only approach Alternatively to the custom deserializer approach, you can have the following for an annotations-only solution (similar to the one described in Spunc’s answer, but using type as an external property): public abstract class AbstractData { private Owner owner; private Metadata metadata; // Getters and setters } public static final class FooData extends AbstractData … Read more

How to prevent null values inside a Map and null fields inside a bean from getting serialized through Jackson

If it’s reasonable to alter the original Map data structure to be serialized to better represent the actual value wanted to be serialized, that’s probably a decent approach, which would possibly reduce the amount of Jackson configuration necessary. For example, just remove the null key entries, if possible, before calling Jackson. That said… To suppress … Read more

Convert JsonNode into POJO

In Jackson 2.4, you can convert as follows: MyClass newJsonNode = jsonObjectMapper.treeToValue(someJsonNode, MyClass.class); where jsonObjectMapper is a Jackson ObjectMapper. In older versions of Jackson, it would be MyClass newJsonNode = jsonObjectMapper.readValue(someJsonNode, MyClass.class);

com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/com.fasterxml.jackson.core/jackson-databind/pom.xml

Instead of this packagingOptions { exclude ‘META-INF/LICENSE’ exclude ‘META-INF/NOTICE’ } try this packagingOptions { exclude ‘META-INF/DEPENDENCIES.txt’ exclude ‘META-INF/LICENSE.txt’ exclude ‘META-INF/NOTICE.txt’ exclude ‘META-INF/NOTICE’ exclude ‘META-INF/LICENSE’ exclude ‘META-INF/DEPENDENCIES’ exclude ‘META-INF/notice.txt’ exclude ‘META-INF/license.txt’ exclude ‘META-INF/dependencies.txt’ exclude ‘META-INF/LGPL2.1’ } and more thing Remove this line apply plugin: ‘com.google.gms.google-services’ from Bottom and add to Top after this apply plugin: ‘com.android.application’. … Read more

How to deserialize JSON into flat, Map-like structure?

You can do this to traverse the tree and keep track of how deep you are to figure out dot notation property names: import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ValueNode; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.junit.Test; public class FlattenJson { String json = “{\n” + ” \”Port\”:\n” + … Read more

Spring @JsonIgnore not working

I have finally found a solution. I changed the import statement from import com.fasterxml.jackson.annotate.JsonIgnore; // com. instead of org. to import org.codehaus.jackson.annotate.JsonIgnore; Basically you have to make sure you are using the same class everywhere.