我有一个json格式的yelp数据集。我正在使用gson映射到POJO。但是,某些键如"Drive-Thru", "Good For"
是连字符或空格分隔。如何为这些类型的键映射POJO类?
{
"business_id":"5UmKMjUEUNdYWqANhGckJw",
"attributes":{
"Take-out":true,
"Drive-Thru":false,
"Good For":{
"dessert":false,
"latenight":false
},
"Caters":false,
"Noise Level":"average",
"Has TV":false,
"Good For Groups":true,
"Wi-Fi":"free",
"Price Range":1
},
"type":"business"
}
我有以下pojo但是对于特殊键类型
,这会返回nullpublic class BusinessPojo {
private String type;
private String business_id;
private BusinessAttributes attributes;
// getters and setters
}
public class BusinessAttributes {
private boolean takeOut;
private boolean driveThru;
private boolean Caters;
private String noiseLevel;
private boolean hasTV;
private String wiFi;
private boolean goodforGroups;
private int priceRange;
private BusinessGoodFor goodFor;
//getters and setters
}
public class BusinessGoodFor {
private boolean dessert;
private boolean latenight;
//getters and setters
}
答案 0 :(得分:0)
Gson提供了“序列化名称”注释:
public class BusinessAttributes {
@SerializedName("Take-out")
private boolean takeOut;
等...