json结构如下:
{
"key":"Key",
"value":{
"first": "first",
"second": "second"
}
}
我想使用Spring Boot将此json作为Plain Old Java Object。
public class File {
private String key;
private JsonObject value;
public File(String key, JsonObject value) {
this.key = key;
this.value = value;
}
public File() {
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public JsonObject getValue() {
return value;
}
public void setValue(JsonObject value) {
this.value = value;
}
}
JsonObject - 来自lib com.google.gson的类 我正进入(状态 {}
将字段“value”作为String获取是完美的,但JsonObject也可以。
完成! com.google.json lib可以使用setter:
public class File {
private String key;
private String value;
public File() {
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(Object value) {
this.value = new Gson().toJson(value);
}
}