-1

I am using Retrofit 2 for API calls and GSON as converter in my Android project. Converted the json to POJO and followed usual methods which are also used in 50+ API in the same project.

But, is this specific scenario, some of the items are being parsed and assigned to the variable while other's are not.

how to resolve this partial parsing ?

Here you can see difference in Android studio debug vs Postman response

enter image description here

Product.class

public class ProductLookup {
    @SerializedName("atsQty")
    @Expose
    private String atsQty;
    @SerializedName("combID")
    @Expose
    private String combID;
    @SerializedName("defaultPickLock")
    @Expose
    private String defaultPickLock;
    @SerializedName("lookupProductPickingLocation")
    @Expose
    private ArrayList<ProductPickingLocation> productPickingLocations = new ArrayList<>();
    @SerializedName("productID")
    @Expose
    private String productID;
    @SerializedName("productName")
    @Expose
    private String productName;
    @SerializedName("totalQty")
    @Expose
    private String totalQty;
    @SerializedName("unitName")
    @Expose
    private String unitName;
    @SerializedName("upc")
    @Expose
    private String upc;
    @SerializedName("vendorName")
    @Expose
    private String vendorName;
    @SerializedName("whName")
    @Expose
    private String whName;

//getter setters 
}

Json response

 {
            "atsQty": 133,
            "combID": 0,
            "defaultPickLock": "FA1",
            "lookupProductPickingLocation": [
                {
                    "availQty": 22,
                    "isdefault": true,
                    "lookupProductBatch": [],
                    "lookupProductLotSerial": [],
                    "pickLockID": 26,
                    "pickingLocationName": "FA1",
                    "prodPickLockID": 77,
                    "totalQty": 27
                },
                {
                    "availQty": 100,
                    "isdefault": false,
                    "lookupProductBatch": [],
                    "lookupProductLotSerial": [],
                    "pickLockID": 27,
                    "pickingLocationName": "FA2",
                    "prodPickLockID": 121,
                    "totalQty": 100
                },
                {
                    "availQty": 6,
                    "isdefault": false,
                    "lookupProductBatch": [],
                    "lookupProductLotSerial": [],
                    "pickLockID": 28,
                    "pickingLocationName": "FB1",
                    "prodPickLockID": 131,
                    "totalQty": 6
                }
            ],
            "productID": 1065,
            "productName": "Arm & Hammer Baking Soda",
            "totalQty": 133,
            "unitName": "",
            "upc": "5454546",
            "vendorName": "Vandelay Industries",
            "whName": "Warehouse 2"
        }
Community
  • 1
  • 1
Sadiq Md Asif
  • 882
  • 6
  • 18

2 Answers2

1

First error i saw here

@SerializedName("lookupProductPickingLocation")
@Expose
private ArrayList<ProductPickingLocation> productPickingLocations = new ArrayList<>();

When you use @Expose,you are actually using productPickingLocations. You can check here for @Expose vs @SerializedName

Use either this

@SerializedName("lookupProductPickingLocation")
private ArrayList<ProductPickingLocation> productPickingLocations = new ArrayList<>();

or

@Expose
private ArrayList<ProductPickingLocation> lookupProductPickingLocation = new ArrayList<>();

Secondly,

@SerializedName("atsQty")
@Expose
private String atsQty;

you defined as String but it can be clearly seen as integer in Postman. i think that is the issue. You need to check all your definitions.

Ferhat Ergün
  • 135
  • 1
  • 10
  • String atsQty; that's not an issue, used it intentionally to use with databinding as they are only view feature. @SerializedName("name") @Expose these are already used in other parts as well, so that's not the root cause of the problem. – Sadiq Md Asif Jan 21 '19 at 14:51
0

Your atsQty combID and totalQty vars looks Integer type and you have used String type in your POJO that's why. Try below code please, hope it helps.

If you are not familiar then Here is the resource where you can get help creating pojo based on your JSON.

ProductLookup.class

public class ProductLookup {

   @SerializedName("atsQty")
   @Expose
   public Integer atsQty;
   @SerializedName("combID")
   @Expose
   public Integer combID;
   @SerializedName("defaultPickLock")
   @Expose
   public String defaultPickLock;
   @SerializedName("lookupProductPickingLocation")
   @Expose
   public List<LookupProductPickingLocation> lookupProductPickingLocation = new ArrayList();
   @SerializedName("productID")
   @Expose
   public Integer productID;
   @SerializedName("productName")
   @Expose
   public String productName;
   @SerializedName("totalQty")
   @Expose
   public Integer totalQty;
   @SerializedName("unitName")
   @Expose
   public String unitName;
   @SerializedName("upc")
   @Expose
   public String upc;
   @SerializedName("vendorName")
   @Expose
   public String vendorName;
   @SerializedName("whName")
   @Expose
   public String whName;

  //getters and setters
}

LookupProductPickingLocation.class

public class LookupProductPickingLocation {

     @SerializedName("availQty")
     @Expose
     public Integer availQty;
     @SerializedName("isdefault")
     @Expose
     public Boolean isdefault;
     @SerializedName("lookupProductBatch")
     @Expose
     public List<Object> lookupProductBatch = null;
     @SerializedName("lookupProductLotSerial")
     @Expose
     public List<Object> lookupProductLotSerial = null;
     @SerializedName("pickLockID")
     @Expose
     public Integer pickLockID;
     @SerializedName("pickingLocationName")
     @Expose
     public String pickingLocationName;
     @SerializedName("prodPickLockID")
     @Expose
     public Integer prodPickLockID;
     @SerializedName("totalQty")
     @Expose
     public Integer totalQty;

//getters and setters.
}
Aalap Patel
  • 2,058
  • 2
  • 17
  • 31