americanexpress / nodes

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

Need Help #43

Closed G-ruchika closed 5 years ago

G-ruchika commented 5 years ago

Looking for some help.. I am using this library into my project. and getting error while deserializing the response. My query : query somethingHere { courses { id } } Response : { "data": { "courses": [ { "id": 1 }, { "id": 2 }, { "id": 3 } ] } }

I have defined the class like this

@Setter @Getter @GraphQLProperty(name = "courses") public class Course { int id; }


@Getter @Setter public class CourseRes{

private List courses; }


try{

  final GraphQLRequestEntity requestEntity = GraphQLRequestEntity.Builder()
      .url("https://nimbus-service.herokuapp.com/courses")
      .request(Course.class)
      .build();
  GraphQLResponseEntity<CourseRes> tmp = new GraphQLTemplate().query(requestEntity, CourseRes.class);
  }catch(Exception e) {
  //throw new VirtualAssistantException(e.getMessage(), e);
  e.printStackTrace();
}

}

Getting below exception com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "courses" (class CourseRes), not marked as ignorable (0 known properties: ]) at [Source: (String)"{"courses":[{"id":1},{"id":2},{"id":3}]}"; line: 1, column: 13] (through reference chain: io.aexp.nodes.graphql.Wrapper["data"]->CourseRes["courses"])

Thanks

chemdrew commented 5 years ago

What package are you using for your @getter and @setter annotations?

I was able to successfully execute the query you have with the getters/setters defined the normal boring way, it shouldn't be an issue though, but I've only tested the shorthand getters/setters with lombok annotations