0

I want my JSON to look like this:

"optInInfoList": {

  "optInInfo": [
    {
      "optInCode": "123445 (max 20)",

      "optInName": "WORDSGOHERE (max 255)",

      "optInDescription": "DESCRIPTION HERE (max 4000)"

    }

  ]
 "optInInfo": [
    {
      "optInCode": "123445 (max 20)",

      "optInName": "WORDSGOHERE (max 255)",

      "optInDescription": "DESCRIPTION HERE (max 4000)"

    }

  ]
}

Code so far:

package com.sprint.eai.createcreditaccountagreement.bo;

public class OptInInfo {

    private String optInCode;
    private String optInName;
    private String optInDescription;

    public OptInInfo() {
    }

    public OptInInfo(String optInCode, String optInName, String optInDescription) {
        this.optInCode = optInCode;
        this.optInName = optInName;
        this.optInDescription = optInDescription;

}

public String getOptInCode() {
    return optInCode;
}

public void setOptInCode(String optInCode) {
    this.optInCode = optInCode;
}

public String getOptInName() {
    return optInName;
}

public void setOptInName(String optInName) {
    this.optInName = optInName;
}

public String getOptInDescription() {
    return optInDescription;
}

public void setOptInDescription(String optInDescription) {
    this.optInDescription = optInDescription;
}

}

And

package com.sprint.eai.createcreditaccountagreement.bo;

import java.util.ArrayList;

public class CreditAccountAgreement {

    private ArrayList<OptInInfo> optInInfoList;

    public CreditAccountAgreement() {
    }

    public ArrayList<OptInInfo> getOptInInfoList() {
        return optInInfoList;
    }

    public void setOptInInfoList(ArrayList<OptInInfo> optInInfoList) {
        this.optInInfoList = optInInfoList;
    }

}

I just missing the part how I can convert the Java object to JSON with Jackson:

private static ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(Include.NON_NULL);

String jsonRequest = mapper.writeValueAsString(cstRequest);
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
Madhav
  • 1
  • 2
    Possible duplicate of [Converting Java objects to JSON with Jackson](http://stackoverflow.com/questions/15786129/converting-java-objects-to-json-with-jackson) – silentsod Dec 14 '16 at 17:44
  • 1
    https://github.com/google/gson – Fabio Venturi Pastor Dec 14 '16 at 18:05
  • Your JSON doesn't make much sense: it contains an object with two attributes with the same name. It doesn't match the structure of your Java object either. But what exactly is the question anyway? You posted the code needed to transform an object to JSON, so what's the problem? – JB Nizet Dec 14 '16 at 18:06

0 Answers0