2

我有一个 JSON 映射,例如:

{ "element":"value","element2":"value2",...}

带有键和值字符串。我尝试用 autobean 阅读它,但我得到了奇怪的例外。它应该是直截了当的,不是吗?

我得到的错误是:

[ERROR] [project_name] - The java.util.Map parameterization is not simple, but the getConf method does not provide a delegate

我是这样读地图的:

final String jsObject = GeneralContextNativeReader.read("globalConf");
GlobalConfFactory globalConfFactory = GWT.create(GlobalConfFactory.class);
Map<String, String> globalConf = AutoBeanCodex.decode(globalConfFactory, Map.class, jsObject).as();

工厂定义为:

public interface GlobalConfFactory extends AutoBeanFactory {
    AutoBean<Map<String, String>> globalConf();
}

那有什么问题?

4

2 回答 2

1

AFAIKMapsLists其他非简单对象只能是引用类型而不是值类型。有关更多详细信息,请参见此处
将代码更改为此应该可以工作:

public interface Data {
   public Map<String,String>> getGlobalConf();
}

public interface DataFactory extends AutoBeanFactory {
   AutoBean<Data> getData();
}

final String jsObject = GeneralContextNativeReader.read("globalConf");
DataFactory dataFactory = GWT.create(DataFactory.class);
Data data = AutoBeanCodex.decode(dataFactory, Data.class, jsObject).as();
Map<String, String> globalConf = data.getGlobalConf();

您的 json 字符串必须看起来像这样:

{"globalConf":{ "element":"value","element2":"value2",...}}
于 2012-08-23T08:39:22.297 回答
0

如果您的 AutoBean 接口包含静态方法(Java 8 中的新方法),也会发生这种情况。

于 2015-08-25T18:11:16.380 回答