2
创建一个工厂JSON解串器我有一大堆的注释界面如下:杰克逊
@MyAnnotation(DefaultImplementation.class)
interface SomeInterface {
...
}
和伴随的实施
class DefaultImplementation implements SomeInterface {
...
}
当我ObjectMapper运行到SomeInterface
我会类型的字段像它反序列化它,就好像它是一个DefaultImplementation
。也就是说,我想在解串过程中编码以下逻辑:
if (staticTypeToDeserialize.isAnnotationPresent(MyAnnotation.class))
deserializeAs(type.getAnnotation(MyAnnotation.class).value());
else
fallBackOnRegularDeserialization();
这不需要我用'@ MyAnnotaiton'为每个接口创建一个mixin吗?这是不可取的。我希望能够轻松地添加使用'@ MyAnnotation'注释的新接口。另外,这需要我修改JSON表示。这在我的设置中也是不可取的。这就是我相信我的反序列化器需要某种形式的工厂的原因(即,基于'@ MyAnnotation'注释,即时创建反序列化器的一种方式) – aioobe