Parse JSON array response using Gson in mule custom connector

138 Views Asked by At

I am trying to parse the JSON response from webservice in my custom connector for Mule 4 here is my JSON response from webservice

{
  "value": [
    {
      "contentType": "plainText",
      "id": "listItems0",
    },
    {
      "contentType": "plainText",
      "id": "listItems0",
    }
  ],
  "Success": ""
}

here is my Java code for response I am referring to

Items.java

import java.util.*;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Items {

@SerializedName("Items")
@Expose
private List<ListItems> ItemsList = null;

public List<ListItems> getValue() {
       return ItemsList;
    }
public void setValue(List<ListItems> Items) {
    this.ItemsList= Items;
}

ListItems.java

import java.util.List;
import java.util.Map;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class ListItems{

      @SerializedName(value = "contentType")
      private String contentType;

      @SerializedName(value = "id")
      private String id;


      public String getContentType() {
        return contentType;
      }

      public void setContentType(String contentType) {
        this.contentType = contentType;
      }

      public String getId() {
        return id;
      }

      public void setId(String id) {
        this.id = id;
      }

}

I tried other answers from here as well but I am not able to get any response.

Due to some restriction I will not be able to share the whole code. but even if I get these files reviewed, it will be most helpful to me.

0

There are 0 best solutions below