Open
Description
Currently parameter of type List doesn't deserialize correctly. It happens because gson used to implement DataConverter doesn't have enough information about the type of the argument during deserialization. Current interface uses Class as a type passed to gson. The solution is to pass Type object returned from Method.getGenericParameterTypes(). The following code works:
@Test
public void testUUIDListGson() throws NoSuchMethodException {
Method m = JsonDataConverterTest.class.getDeclaredMethod("foo", List.class);
Type arg = m.getGenericParameterTypes()[0];
GsonBuilder gsonBuilder =
new GsonBuilder()
.serializeNulls();
Gson gson = gsonBuilder.create();
List<UUID> list = new ArrayList<>();
for (int i = 0; i < 2; i++) {
list.add(UUID.randomUUID());
}
String data = gson.toJson(list);
List<UUID> result = gson.fromJson(data, arg);
assertEquals(result.toString(), list, result);
}
The proposal is to change DataConverter API to either accept Method as a parameter or list of Type objects.