Gson忽略实例创建者

时间:2014-07-30 19:09:54

标签: gson

我正在定义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.

有什么理由可以忽略这一点吗?

0 个答案:

没有答案