This is related to a previous question that I asked here earlier
我试图解析同一个JSON,但现在我稍微改变了我的类.
{
"lower": 20,
"upper": 40,
"delimiter": " ",
"scope": ["${title}"]
}
我的班级现在看起来是这样的:
public class TruncateElement {
private int lower;
private int upper;
private String delimiter;
private List<AttributeScope> scope;
// getters and setters
}
public enum AttributeScope {
TITLE("${title}"),
DESCRIPTION("${description}"),
private String scope;
AttributeScope(String scope) {
this.scope = scope;
}
public String getScope() {
return this.scope;
}
}
This code throws an exception,
com.google.gson.JsonParseException: The JsonDeserializer EnumTypeAdapter failed to deserialized json object "${title}" given the type class com.amazon.seo.attribute.template.parse.data.AttributeScope
at
这个异常是可以理解的,因为根据我前面问题的解决方案,GSON希望实际创建的Enum对象是
${title}("${title}"),
${description}("${description}");
但既然这在语法上是不可能的,那么推荐的解决方案和变通方法是什么?