我正在定义InstanceCreator
并通过GsonBuilder
注册,如下所示:
final GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(java.awt.Shape.class, new ShapeInstanceCreator<>());
final Gson gson = gsonBuilder.create();
但是,我仍然收到以下错误,并且在反序列化JSON时从未看到调用InstanceCreator
:
Exception in thread "main" java.lang.RuntimeException: Unable to invoke no-args constructor for interface java.awt.Shape. Register an InstanceCreator with Gson for this type may fix this problem.
有什么理由可以忽略这一点吗?