I have a JSON map like:
{ "element":"value","element2":"value2",...}
With both key and value strings. I try to read it with an autobean and I get strange exceptions. It should be straightforward, shouldn't?
The error I'm getting is:
[ERROR] [project_name] - The java.util.Map parameterization is not simple, but the getConf method does not provide a delegate
I read the map like that:
final String jsObject = GeneralContextNativeReader.read("globalConf");
GlobalConfFactory globalConfFactory = GWT.create(GlobalConfFactory.class);
Map<String, String> globalConf = AutoBeanCodex.decode(globalConfFactory, Map.class, jsObject).as();
and the factory is defined as:
public interface GlobalConfFactory extends AutoBeanFactory {
AutoBean<Map<String, String>> globalConf();
}
What is wrong with that ?
AFAIK Maps
and Lists
and other non simple objects can only be reference types and not value types. See here for more details.
Changing the code to this should make it work:
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();
Your json string has to look something like that:
{"globalConf":{ "element":"value","element2":"value2",...}}