我有一个简单的POJO类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;
}
而且我尝试转换Gson.JsonObject
到Defect
。该JsonObject
看起来是这样的:
我想只存储特定的领域,因此不会在POJO所有添加的。
但是new GsonBuilder().create().fromJson(object, Defect.class)
返回将所有Defect
值的null
对象。这里有什么问题?
您的JSON元素是从POJO成员,结果正确映射情况并非如此不同。请注释formattedId为
@SerializedName("FormattedID")
private String formattedId;
使formattedId工作。