americanexpress / nodes

A GraphQL JVM Client - Java, Kotlin, Scala, etc.
Apache License 2.0
307 stars 70 forks source link

Problem Deserializing an Empty List #116

Open trizzle21 opened 3 years ago

trizzle21 commented 3 years ago

Hello! I'm having a small issue with a graphQL request that returns an empty list. I'm currently querying the Shopify Bulk Ingestion with a request payload that looks like:

query { 
     bulkOperationRunQuery (query:"long query") {
        userErrors { 
              field 
              message 
        } bulkOperation { 
              id 
             status 
        } 
    } 
} 

which has a response that looks like

{
  "data": {
    "bulkOperationRunQuery": {
      "bulkOperation": {
        "id": "gid:\/\/shopify\/BulkOperation\/720918",
        "status": "CREATED"
      },
      "userErrors": []
    }
  }
}

I have my objects that look like

public class BulkIngestionQueryOperation {

    @GraphQLArgument(name="query", type="String")
    private BulkOperationRunQuery bulkOperationRunQuery;

    public BulkOperationRunQuery getBulkOperationRunQuery() {
        return bulkOperationRunQuery;
    }

    public void setBulkOperationRunQuery(BulkOperationRunQuery bulkOperationRunQuery) {
        this.bulkOperationRunQuery = bulkOperationRunQuery;
    }
}

@GraphQLProperty(name="bulkOperationRunQuery", arguments={
        @GraphQLArgument(name="query")
})
public class BulkOperationRunQuery {
    private BulkOperation bulkOperation;
    private UserErrors userErrors;

    public BulkOperation getBulkOperation() {
        return bulkOperation;
    }

    public void setBulkOperation(BulkOperation bulkOperation) {
        this.bulkOperation = bulkOperation;
    }

    public UserErrors getUserErrors() {
        return userErrors;
    }

    public void setUserErrors(UserErrors userErrors) {
        this.userErrors = userErrors;
    }
}

public class UserErrors {
    private String message;
    private String field;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }

    public String toString() {
        return "error on " + field + " due to " + message;
    }
}

When I screw up the user fields and I get a UserError, my request deserializes correctly. However, when the request is successful, I get an empty list of UserErros to which I get the error,

'Cannot deserialize instance of `com.attentivemobile.bulk.ingestion.processor.model.graphql.UserErrors` out of START_ARRAY token
 at [Source: (String)"{"bulkOperationRunQuery":{"userErrors":[],"bulkOperation":{"id":"gid://shopify/BulkOperation/xxxxxxxxxxx","status":"CREATED"}}}"; line: 1, column: 40] 

Is there a feature or trick with that I'm not aware of or is this a known issue?

I know there are similar issues here, but they have a very different schema, doesn't involve an empty list and the solution involves moving the arguments to the nested object which is already the case here.

Thanks so much in advance!!

Tyler