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:
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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.