These are the values from the input JSON to be mapped to the POJO class.
"{"data":{"getUserInformation":{"CreationDate":"22.07.2021 10:24:53","Email":"test@b.de","User":{"UserName":"testUser20SK","LoggingEnabled":null},"State":"FORCE_CHANGE_PASSWORD","Verified":true}}}"
The mapping logic is as below:
String response = appsyncGraphQLClient.execute(HttpMethodName.POST, new ByteArrayInputStream(query.getBytes())).getBody();
JsonNode data = new ObjectMapper().readTree(response).path("data").path("getUserInformation");
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.treeToValue(data,CognitoUser.class);
I am not getting any values in the POJO from the JSON. All the variables are showing as null. What could be I am missing here?
My POJO CLass is generated from auto gen feature from a Graphql schema
type CognitoUser {
CreationDate: String
Email: String!
State: String
User: User
Username: String!
Verified: Boolean
}
POJO Class
@javax.annotation.Generated(
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2021-07-22T13:02:27+0200"
)
public class CognitoUser implements java.io.Serializable {
private String CreationDate;
@javax.validation.constraints.NotNull
private String Email;
private String State;
private User User;
@javax.validation.constraints.NotNull
private String Username;
private Boolean Verified;
public CognitoUser() {
}
public CognitoUser(String CreationDate, String Email, String State, User User, String Username, Boolean Verified) {
this.CreationDate = CreationDate;
this.Email = Email;
this.State = State;
this.User = User;
this.Username = Username;
this.Verified = Verified;
}
public String getCreationDate() {
return CreationDate;
}
public void setCreationDate(String CreationDate) {
this.CreationDate = CreationDate;
}
public String getEmail() {
return Email;
}
public void setEmail(String Email) {
this.Email = Email;
}
public String getState() {
return State;
}
public void setState(String State) {
this.State = State;
}
public User getUser() {
return User;
}
public void setUser(User User) {
this.User = User;
}
public String getUsername() {
return Username;
}
public void setUsername(String Username) {
this.Username = Username;
}
public Boolean getVerified() {
return Verified;
}
public void setVerified(Boolean Verified) {
this.Verified = Verified;
}
Edit: I have found out what could be the problem but not able to get corerct solution
JsonNode is storing value under children like below: (Got this from debug)
result = {ObjectNode@3642} "{"CreationDate":"22.07.2021 10:24:53","Email":"test@lb.de","User":{"UserName":"testUser20SK","LoggingEnabled":null},"State":"FORCE_CHANGE_PASSWORD","Verified":true}"
_children = {LinkedHashMap@4442} size = 5
"CreationDate" -> {TextNode@4452} ""22.07.2021 10:24:53""
"Email" -> {TextNode@4454} ""test@lb.de""
"User" -> {ObjectNode@4456} "{"UserName":"testUser20SK","LoggingEnabled":null}"
"State" -> {TextNode@4458} ""FORCE_CHANGE_PASSWORD""
"Verified" -> {BooleanNode@4460} "true"
_nodeFactory = {JsonNodeFactory@4443}
I used
objectMapper.readValue(data.get("children").asText(),CognitoUser.class);`
but it is not giving result. `