0

I have a simple POJO class Defect:

 import lombok.Getter; import lombok.Setter; import lombok.ToString; @Setter @Getter @ToString public class Defect { private String formattedId; private String fixedInBuild; private String foundInBuild; private String verifiedInBuild; private String state; private String resolution; private String submittedBy; private String priority; private String severity; } 

And I am trying to convert a Gson.JsonObject to Defect. The JsonObject looks like this:

enter image description here

I want to store only specific fields hence not all added in the POJO.

But new GsonBuilder().create().fromJson(object, Defect.class) returns a Defect object with all null values. What is wrong here?

1
  • 1
    Looks like the elements in the Json itself have different names (different case) than the fields in the POJO. You should set a naming policy in the GsonBuilder before the create. Commented Feb 3, 2019 at 12:07

1 Answer 1

3

Your json elements are different from the POJO members as a result proper mapping is not happening. Please annotate formattedId as

@SerializedName("FormattedID") private String formattedId; 

to make formattedId work.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.