-1

below written is my input json:

{
    "apiData": [{
        "apiName": "API",
        "arguments": [{
            "callFlow": "A"
        }, {
            "directoryName1": "CFAActivation"
        }, {
            "recDurationIVR1": "6000"
        }, {
            "numToDial": "*72"
        }, {
            "sleepDuration": "0000"
        }],
        "step": "1" 
    }]
}

//here "arguments" json array has dynamic json objects..

bhspencer
  • 13,086
  • 5
  • 35
  • 44

1 Answers1

-1

Respected Java Class According to your JSON

public class Arguments
 {
  private String callFlow;

     public String getCallFlow ()
    {
       return callFlow;
    }

    public void setCallFlow (String callFlow)
     {
    this.callFlow = callFlow;
     }

    @Override
    public String toString()
    {
    return "ClassPojo [callFlow = "+callFlow+"]";
    }
}


 public class ApiData
 {
   private Arguments[] arguments;

    private String apiName;

   private String step;

  public Arguments[] getArguments ()
{
    return arguments;
}

public void setArguments (Arguments[] arguments)
{
    this.arguments = arguments;
}

public String getApiName ()
{
    return apiName;
}

public void setApiName (String apiName)
{
    this.apiName = apiName;
}

public String getStep ()
{
    return step;
}

public void setStep (String step)
{
    this.step = step;
}

@Override
public String toString()
{
    return "ClassPojo [arguments = "+arguments+", apiName = "+apiName+", step = "+step+"]";
}
}

 public class Jobj
{
private ApiData[] apiData;

public ApiData[] getApiData ()
{
    return apiData;
}

public void setApiData (ApiData[] apiData)
{
    this.apiData = apiData;
}

@Override
public String toString()
{
    return "ClassPojo [apiData = "+apiData+"]";
}
}
Negi Rox
  • 3,828
  • 1
  • 11
  • 18
  • In the above snippet, how the Arguments class would handle dynamic json structure? – Vishal Raja Jan 11 '18 at 15:26
  • you can see the getter and setter. in this class. – Negi Rox Jan 11 '18 at 16:02
  • getter and setters are only for CallFlow attribute but as per the json, Arguments is actually an array with dynamic number of attributes. – Vishal Raja Jan 11 '18 at 16:10
  • bro this is sample class according to your json. but if you want functionality then it might be same thing like this post. https://stackoverflow.com/questions/5015844/parsing-json-object-in-java – Negi Rox Jan 11 '18 at 16:15
  • you can use this class object to store your JSON object data correspondingly – Negi Rox Jan 11 '18 at 16:16
  • Hi Negi Rox, for the next iteration the arguments array will be like given below { "apiData": [{ "apiName": "API", "arguments": [{ "callerID": "2211" }, { "tune": "xxxx" }, { "rate": "6.0" }, { "number": "76" }, { "timeinterval": "57" }], "step": "1" }] } so i need to create getter setter for all parameters (i.e) callerID, tune, rate, number, timeinterval? – Dhakshina Moorthy Jan 12 '18 at 06:10
  • json objects key will be varying each time. is there any method to map this to java class object? – Dhakshina Moorthy Jan 12 '18 at 07:12
  • Then you need to store whole array as string in a db – Negi Rox Jan 12 '18 at 09:23