I'm trying to go all-JSON-B in my application so I ditched gson for de-serializing my json-configuration. I have something like
Jsonb jsonb = JsonbBuilder.create(config); String json = getConfigJson(configFile); Type type = new ArrayList() {}.getClass().getGenericSuperclass(); Collection environment = jsonb.fromJson(json, type);
gson had TypeToken but many JSON-B tutorials appear to use the above way of getting the generic type information. I see in the debugger that type is
java.util.ArrayList<fqcn.Environment>
but I still get a javax.json.bind.JsonbException: Can't create instance of a class: interface java.util.Collection, No default constructor found. Am I doing it all wrong or is something that is different from Java SE when I run it in-container (application-scoped producer method for loading the configuration)? Testing on WF14
Edit: I actually verified this by making a Java SE-project with the javax.json:javax.json-api:1.1.4 & org.glassfish:javax.json:1.1.4 & javax.json.bind:javax.json.bind-api:1.0 & org.eclipse:yasson:1.0.3 and there I was able to deserialize with that same Type. Strange.
Thanks in advance,
Nik
Message was edited by: Nicklas Karlsson Java SE test
Ngh, I tested in SE with too recent versions. Upgrading to WF16 appears to have fixed the issue (which probably have the more recent implementations). The issue was probably with a nested Collection...