Tags down


How to consume the inconsistent json structure for the same key using jackson (com.fasterxml.jackson)?

By : Rana Babu
Date : October 18 2020, 06:10 AM
help you fix your problem Generally Jackson converts JSON Array to List and JSON Object to Map. We can use general Object type in this case and it will be properly set. We just need to check which type we have in given case and properly cast to right Java type. See below example:
code :
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.util.List;
import java.util.Map;

public class JsonApp {

    public static void main(String[] args) throws Exception {
        File jsonFile = new File("./resource/test.json").getAbsoluteFile();

        ObjectMapper mapper = new ObjectMapper();
        TypeReference<List<Item>> typeReference = new TypeReference<List<Item>>() {
        List<Item> items = mapper.readValue(jsonFile, typeReference);

        items.forEach(item -> {
            if (item.isArray()) {
                System.out.println("List => " + item.getFileMetaDataAsList());
            } else if (item.isObject()) {
                System.out.println("Map => " + item.getFileMetaDataAsMap());


class Item {

    private String fileName;
    private Object fileMetaData;

    public String getFileName() {
        return fileName;

    public void setFileName(String fileName) {
        this.fileName = fileName;

    public Object getFileMetaData() {
        return fileMetaData;

    public void setFileMetaData(Object fileMetaData) {
        this.fileMetaData = fileMetaData;

    public boolean isObject() {
        return this.fileMetaData instanceof Map;

    public boolean isArray() {
        return this.fileMetaData instanceof List;

    public Map<String, Object> getFileMetaDataAsMap() {
        return (Map<String, Object>) this.fileMetaData;

    public List<Map<String, Object>> getFileMetaDataAsList() {
        return (List<Map<String, Object>>) this.fileMetaData;

    public String toString() {
        return "Item{" +
                "fileName='" + fileName + '\'' +
                ", fileMetaData=" + fileMetaData +
Map => {abcd=valueabcd, xyz=valuexyz}
List => [{123=value123, 456=value456}, {123=value123-1, 456=value456-1}]
Map => {key1={key11=val11, key12=val22}, key2=val2}

Share : facebook icon twitter icon

Jackson error: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/Versioned

By : Crazy One
Date : March 29 2020, 07:55 AM
this will help Couettos, it works, I checked the versions of application server and the maven jars then I downloaded the latest 2.4.0 jackson jars and upgrade the glassfish lib jars with the 2.4.0 version

Jackson error com.fasterxml.jackson.databind.ser.ContainerSerializer: method <init>(Lcom/fasterxml/jackson/databin

By : Kartikeya Vyas
Date : March 29 2020, 07:55 AM
seems to work fine Probably the container has already an older version of Jackson and that is making class loading problems.
A way to solve that can be specifying a jboss-deployment-structure.xml file. That way you can "inject" your dependencies with higher priority. See this classloading problems with Wildfly 8.0.0 for more details and example.

Getting ClassNotFoundException: com.fasterxml.jackson.core.JsonProcessingException when calling Jackson JSON parser from

By : trungkho
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further This problem is almost certainly caused by classloaders within your servlet container (Tomcat 8.x) being unable to locate the library/JAR for Jackson. The way classes/libs are loaded within servlet containers is different than a standard classpath declaration from a standalone Java application. This is why you are seeing the error from the servlet engine but not during your direct execution of the class. Here is the general documentation on how Tomcat 8.x handles classloading:

com.fasterxml.jackson.databind.exc.MismatchedInputException while parsing json reply into object using fasterxml

By : Saad Naufel
Date : March 29 2020, 07:55 AM
I hope this helps . The JSON you are using is in incorrect even when unescaped Therefore it is treating the whole object as a String. Using the correct escaped json will solve the problem,i have corrected the JSON for you have a look now weather it works
code :
{\r\n\t\"topic\": \"trading\/offers\/BTC-PLN\",\r\n\t\"message\": {\r\n\t\t\"entryType\": \"Buy\",\r\n\t\t\"rate\": \"22000.0\",\r\n\t\t\"action\": \"update\",\r\n\t\t\"offerId\": \"b96f2da7-55f9-4221-aaa3-8e3ad177567d\",\r\n\t\t\"market\": \"BTC-PLN\",\r\n\t\t\"state\": {\r\n\t\t\t\"market\": \"BTC-PLN\",\r\n\t\t\t\"offerType\": \"Buy\",\r\n\t\t\t\"id\": \"b96f2da7-55f9-4221-aaa3-8e3ad177567d\",\r\n\t\t\t\"currentAmount\": \"0.0005\",\r\n\t\t\t\"lockedAmount\": \"11.00\",\r\n\t\t\t\"rate\": \"22000.0\",\r\n\t\t\t\"startAmount\": \"0.0005\",\r\n\t\t\t\"time\": \"1535023208260\",\r\n\t\t\t\"postOnly\": false,\r\n\t\t\t\"hidden\": false,\r\n\t\t\t\"mode\": \"limit\",\r\n\t\t\t\"receivedAmount\": \"0\"\r\n\t\t}\r\n\t},\r\n\t\"timestamp\": 1535023208264\r\n}
public class WsOrderReply {

        private final String topic;
        private final Message message;
        private final Long timestamp;
        ObjectMapper mapper = new ObjectMapper();

        public WsOrderReply(
                @JsonProperty("topic") String topic,
                @JsonProperty("message") String messageString,
                @JsonProperty("timestamp") Long timestamp) {
            this.topic = topic;
            this.message = mapper.readValue(messageString, Message.class);;
            this.timestamp = timestamp;

Upgrade of Jackson from org.codehaus.jackson to com.fasterxml.jackson (version 1.9.13 --> 2.9.8)

By : user2709376
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Following are some of the changes identified between Jackson 1.9.x and Jackson 2.9.8
1. org.codehaus.jackson changed to com.fasterxml.jackson
Related Posts Related Posts :
  • How to modify camel Exchange and send it
  • How do I avoid constructors?
  • Passing string in where clause using PreparedStatement
  • Tomcat 7 - Ignoring db conections pool parameters (DBCP)
  • How does reduce() method work with parallel streams in Java 8?
  • How can I use a generic class with wildcard declaration?
  • Unable to add ArrayList with multiple arguments
  • Move application into second window monitor in javafx
  • does intern() method have implication on performance?
  • How to run NPM Command in Java code using ProcessBuilder
  • Sending HTTP/2 request via Socket in Java
  • eclipse IDE wrong warning that unused field
  • Decode Java enum from single char
  • How to hide embedded dependencies when using an OSGI bundle with maven?
  • How to correctly implement a generic interface in Java
  • send alert to html page from servlet
  • <EOF>Exception while creating Derby table
  • What does stack.pop() return?
  • Problem with Java Language Levels in IntelliJ IDEA
  • How do i get the status code for a response i subscribe to using the JDK's HttpClient?
  • How should my INSERT INTO statement for GENERATED BY DEFAULT AS IDENTITY be?
  • What is a good way to allow only one non null field in an object
  • Java Runtime only recognizes class file versions up to 52.0 even when java 11 is installed
  • For loop an arraylist for each first two elements separated by comma in Java
  • Filter values from a list based on priority
  • In java, how can i declare a variable inside an if lambda condition?
  • How to XOR a String using a byte array as key?
  • Print Statement in Loop Repeats Multiple Times
  • Generating unique value in java give duplicate
  • How to fix 'handleWindowVisibility: no activity for token android.os.BinderProxy'?
  • Memory issue - InputStream/OutputStream
  • Download a .csv file Java6
  • Why NavigableSet JavaDoc states about implementation details?
  • How to create health check in Grafana?
  • What is the optimal way to call N blocking api calls in parallel to get most out of CPU while waiting for api calls to c
  • How to control text in edittext after key is pressed?
  • NullPointerException when starting a Popupwindow with default values set, otherwise it works
  • How to filter a dataset according to datetime values in Spark
  • RegEx for matching commas inside array values
  • Program won't continue when pressing enter. How do I fix this error?
  • Trying to increment counter using character comparison
  • Convert list into String with values
  • Avoiding major/minor version conflicts with Java/Maven dependencies
  • Lag a value with Datavec transform
  • Lower bound generic in java does not compile even when passing super class
  • Why CompletableFuture.runAsync is not executed?
  • How can I make the ball go where it is supposed to go after it is hit by the stick?
  • Spring -- allow overriding THAT particular bean only
  • Can i mock file.mkdirs() which is inside of a method
  • How to get .crt file from .jks
  • How to remove characters from String Value?
  • Unit Testing a Public method with private supporting methods inside of it?
  • JavaFX when button press draw rectangle with dimensions in textField and find if they intersect
  • pushing to hashmap of lists
  • Execution failed for task ':app:transformClassesAndResourcesWithR8ForRelease' while generating signed apk/bundle
  • log4j2 generates folder with older date - Springboot
  • Java casting mystery - Class.cast vs cast operator
  • Android sending notification from application A to application B
  • Libgdx Clearing Screen benefits
  • Asynchronous Lambda Proxy integration
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk