我有一个枚举类
public enum CacheType {
NONE("none"), NONSTRICT_READ_WRITE("nonrestrictreadwrite"), READ_ONLY("readonly"), READ_WRITE("readwrite");
private final String text;
private CacheType(final String text) {
this.text = text;
}
@JsonValue
public String getText()
{
return text;
}
}
现在我有Table类
public class Table {
private CacheType cachetype;
.... getters and setters
}
现在,如果将json发送到spring控制器,则Table
的设置正确cachetype
。直到现在一切都还好。
现在我在做Unit Test
所以我读了json测试文件,如下所示,并将其转换为Object:
import com.fasterxml.jackson.databind.ObjectMapper;
private final ObjectMapper mapper = new ObjectMapper();
table= mapper.readValue(file, Table.class);
此处cachetype
始终设为NULL
。其余的表属性设置正确。我如何正确阅读cachetype
{
"tables":[
{
"name": "DummyUsers",
"namespace": "",
"cachetype": "readwrite"
},
{
"name": "AdminUsers",
"namespace": "",
"cachetype": "nonrestrictreadwrite"
},
{
"name": "SuperUsers",
"namespace": "",
"cachetype": "none"
}
]
}