gpt4 book ai didi

java - GWT Autobean Codex 读取 map

转载 作者:行者123 更新时间:2023-11-30 11:41:53 24 4
gpt4 key购买 nike

我有一个像这样的 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

我是这样看 map 的:

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();
}

这有什么问题吗?

最佳答案

AFAIK MapsLists 以及其他非简单对象只能是引用类型,不能是值类型。参见 here了解更多详情。
将代码更改为此应该可以正常工作:

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",...}}

关于java - GWT Autobean Codex 读取 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12076550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com