1

Is there any way I could convert the following JSON into a single POJO? There are online convertors that makes conversions but they create multiple classes. Is there a way I could do this by just having it as a Map within a Map within a Map....

I do not want to have to use any external libraries for this. Thanks.

My JSON

{
  "offerMap": {
    "1000": {
      "HEADER": {
        "SIGNAL": "some signal data",
        "TERMS_COPY": "Terms and Conditions for... ",
        "TERMS_LINK": "www.abc.com",
        "LABEL": "a label",
        "CARD_PIC": "art.png",
        "CARD_PICS_TO_SELECT": {
          "12345213765": {
            "LABEL": "card one",
            "CARD_IMG": "one.png"
          },
          "8734529384": {
            "LABEL": "card two",
            "CARD_IMG": "two.png"
          }
        }
      },
      "PERS": {
        "PERS_EXTRA_COPY": "some copy data",
        "PERS_CURRENCY": "some currency"
      },
      "OTHERS": {},
      "EMAIL": {
        "EMAIL_COPY": "email copy"
      }
    }
  }
}

I tried the following but it throws an error saying:

cannot deserialize instance of string out of start_object token

private Map<String, Map<String, Map<String, Object>>> offerMap;

public Map<String, Map<String, Map<String, Object>>> getOfferMap() {
    return offerMap;
}

public void setOfferMap(
        Map<String, Map<String, Map<String, Object>>> offerMap) {
    this.offerMap = offerMap;
}
karvai
  • 2,417
  • 16
  • 31
  • Since you are not looking for multiple classes, I am assuming you have no reason to capture each portion as its own class. So could you just try -> Map offerMap; . You will need to do some casting when you try to capture a value. – Trevor_zam Sep 21 '18 at 17:45

0 Answers0