Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:19:50+00:00 2026-06-14T19:19:50+00:00

EDIT: by request of some of you I’m posting my real data structures and

  • 0

EDIT: by request of some of you I’m posting my real data structures and classes. I failed in trying to make it easier for you to understand the problem.

I have a problem in resolving with Jackson null JSON array elements, ending up with an exception that I’ll report later in this post.

I have a long-winded JSON string coming from a 3rd party provider:

[
  null,
  null,
  [
    {
      "t" : {
        "id" : 0,
        "it" : "Attuazione"
      },
      "c" : "DM.10.0.2",
      "l" : "Macro 2",
      "v0" : 0,
      "scid" : "1",
      "m" : "10",
      "sam" : 0,
      "v1" : 100,
      "smcm" : true,
      "w" : "OD.10.4",
      "st" : {
        "auto_formula" : {
          "ia" : "($x > 0 ? 1 : 0)",
          "id" : "($x > 0 ? 1 : 0)",
          "bit" : "($x > 0 ? 1 : 0)",
          "oa" : "($x > 0 ? 1 : 0)",
          "od" : "($x > 0 ? 1 : 0)",
          "dm" : "($x > 0 ? 1 : 0)"
        },
        "id" : 0,
        "css_rule" : "containerTypeOnOff",
        "default_measure_unit" : null,
        "it" : "On \/ Off",
        "widget" : {
          "id" : 0,
          "caption" : {
            "it" : "Etichetta di testo"
          }
        }
      }
    }
  ],
  null,
  null,
  null,
  null,
  null
]

My Java classes ensemble is the following.

This is the outmost container:

public class TinyMap {
    ArrayList<TinyMapModule> modules;

    public TinyMap() { ...  }

    public ArrayList<TinyMapModule> getModules() { ... }

    /**
     * @param modules the modules to set
     */
    @SuppressWarnings("unchecked")
    public void setModules(ArrayList<TinyMapModule> modules) { ... }

    public void appendNewMacro(TinyMapModule m) { ... }

}

And this is the first-level container:

public class TinyMapModule {
    private ArrayList<TinyMapMacro> macros;

    /**
     * C'tor 
     */
    public TinyMapModule() { ... }

    /**
     * @return ArrayList<TinyMapMacro> 
     */
    public ArrayList<TinyMapMacro> getMacros() { ... }

    /**
     * @param macros the macros to set
     */
    @SuppressWarnings("unchecked")
    public void setMacros(ArrayList<TinyMapMacro> macros) { ... }

}

And this is the innermost level:

public class TinyMapMacro {
    private String c; 
    private String l;
    private String m;
    private MacroType t;
    private String w;

    private static Logger logger;

    static {
        logger = Logger.getLogger(TinyMapMacro.class);
        DOMConfigurator.configure("log4j.xml");
    }

    /**
     * C'tor 
     */
    public TinyMapMacro() { ... }

    public static class MacroType {
        private int id;
        private String it; // Italian

        public int getId() { ... }
        public void setId(int id) { ... }
        public String getIt() { ... }
        public void setIt(String it) { ... }
    }

    public String getC() { ... }

    public void setC(String c) { ... }

    public String getL() { ... }

    public void setL(String l) { ... }

    public String getM() { ... }

    public void setM(String m) { ... }

    public MacroType getT() { ... }

    public void setT(MacroType t) { ... }

    public String getW() { ... }

    public void setW(String w) { ... }

    public int getTypeId() { ... }

    public String getLocalizedTypeString() { ... }

}

Finally, this is my deserialization code:

ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);
ObjectReader reader = mapper.reader(TinyMapModule.class);
try {
    logger.info("Instantiating ObjectMapper");
    TinyMap tm = new TinyMap();
    tm.buildTinyMap(reader.readValues(jsonString.replaceAll("null", "[{\"name\":\"\"}]")));
    for (int i = 0; i < tm.getModules().size(); i++) {
        if (tm.getModules().get(i) == null) 
            continue;
        for (int j = 0; j < tm.getModules().get(i).getMacros().size(); j++) {
            if (tm.getModules().get(i).getMacros().get(j) == null) 
                continue;
            System.out.println(String.format("c: %s", tm.getModules().get(i).getMacros().get(i).getC()));
            System.out.println(String.format("l: %s", tm.getModules().get(i).getMacros().get(i).getL()));
            System.out.println(String.format("m: %s", tm.getModules().get(i).getMacros().get(i).getM()));
            System.out.println(String.format("t.id: %d", tm.getModules().get(i).getMacros().get(i).getTypeId()));
            System.out.println(String.format("t.it: %s", tm.getModules().get(i).getMacros().get(i).getLocalizedTypeString()));
            System.out.println(String.format("w: %s", tm.getModules().get(i).getMacros().get(i).getW()));
        }
    }
    logger.info("Execution terminated");
} 
... 

In extreme synthesis, I tried to schematize the problem as follows:

  1. TinyMap class has a modules member, which is an ArrayList of TinyMapModule objects
  2. TinyMapModule class has a macros member, which is an ArrayList of TinyMapMacro objects
  3. TinyMapMacro class maps objects with the only attributes I strictly need.

Now, when I try to deserialize the above JSON string into my objects I get an exception telling me that JSON can’t be deserialized:

Exception in thread "main" com.fasterxml.jackson.databind.RuntimeJsonMappingException: Can not deserialize instance of it.asystelsrl.hcsbridge.communication.TinyMapModule out of START_ARRAY token
 at [Source: java.io.StringReader@3c50507; line: 1, column: 2]
    at com.fasterxml.jackson.databind.MappingIterator.next(MappingIterator.java:122)
    at it.asystelsrl.hcsbridge.communication.TinyMap.buildTinyMap(TinyMap.java:47)
    at it.asystelsrl.hcsbridge.tests.TestTinyMap.main(TestTinyMap.java:69)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of it.asystelsrl.hcsbridge.communication.TinyMapModule out of START_ARRAY token
 at [Source: java.io.StringReader@3c50507; line: 1, column: 2]
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
    at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:599)
    at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:593)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromArray(BeanDeserializer.java:531)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:141)
    at com.fasterxml.jackson.databind.MappingIterator.nextValue(MappingIterator.java:188)
    at com.fasterxml.jackson.databind.MappingIterator.next(MappingIterator.java:120)
    ... 2 more

I already read a lot about Jackson annotations, custom deserializers, etc. but the only solution I seem to come up with is to convert the TinyMap.modules member from ArrayList<TinyMapModules> to ArrayList<Object> and use a custom deserializer to handle NullType objects.

By this choice (if feasible, because I have not tested it yet) I would lose semantic value of the TinyMap.modules member, and I wouldn’t be forced to.

Is there another way I can resolve the null elements issue?

EDIT:

It is important I can preserve ordinal position of non-null objects within this structure, so I should definitely at least replace null elements with something usable as a placeholder.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:19:51+00:00Added an answer on June 14, 2026 at 7:19 pm

    The problem here is that I made a lot of confusion using Jackson.

    I came to understand it reading this article by ProgrammerBruce.

    I was trying to deserialize a Collection into something which it is not, as StaxMan suggested in his comment.

    Thanks to ProgrammerBruce for his useful and clear article.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this to make a web request and download some data: public partial
Edit Make sure you don't juxtapose the request and response objects. things will be
I am trying to make a view that allows a user to edit a
I'm trying to display some checkbox in a form after getting the data from
I have some methods which take some time to process to fetch data, perform
I'm making a small project to learn Django, and i'm having some problems trying
I am having some issues creating a macro >.>.. And would like to request
I want to send a request to some server just before the phone shuts
I'm poking through some old code and I came across this: if ($_REQUEST['edit']['term']) {
Is there a way to edit the Request.Form before the action method binds to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.