1

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.

aled
  • 21,330
  • 3
  • 27
  • 34
Bora M.s.
  • 141
  • 7
  • You mentioned about a custom connector. Can you tell more about it? Is it based on XML SDK or Java SDK? How are you converting the JSON right now and what is the issue that you are facing? – Harshank Bansal Aug 03 '22 at 13:34
  • Java SDK. while making a call to webservice I am referring to the Items.java file to format the response to json output. – Bora M.s. Aug 03 '22 at 16:39
  • Okay, so you are calling the web service using Java. Can you share the few lines of code showing how you are trying to convert the response to `Items` Object. By the looks of it you have defined `@SerializedName("Items")` for the list, however you are getting `value` in response. But can't say for sure as I don't know if you are maybe doing some other transformation to response before converting, so the code and the error will be helpful – Harshank Bansal Aug 03 '22 at 17:50
  • Is it a requirement to use the GSON library or any other methods to transform the JSON input to the Java classes shared is acceptable? – aled Aug 04 '22 at 00:49

0 Answers0