如何使更快的XML ObjectMapper与Codehaus注释一起使用 [英] How to make fasterxml ObjectMapper work with codehaus annotations

查看:161
本文介绍了如何使更快的XML ObjectMapper与Codehaus注释一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用来自fastxml包(com.fasterxml.jackson.databind.ObjectMapper)中的ObjectMapper类来序列化一些POJO.我面临的问题是POJO中的所有注释均来自较旧的codehaus库. fastxml ObjectMapper无法识别codehaus jackson批注.一种可能的解决方案是将POJO中的注释更新为fastxml,但是POJO由第三方提供,因此我无法对其进行修改.请提出解决此问题的方法.

I'm using the ObjectMapper class from the fasterxml package (com.fasterxml.jackson.databind.ObjectMapper) to serialize some POJOs. The problem I'm facing is that all the annotations in the POJOs are from the older codehaus library. The fasterxml ObjectMapper is not recognizing the codehaus jackson annotations. One possible solution is to update the annotations in the POJO to fasterxml, but the POJOs are provided by a third party, hence I cannot modify it. Please suggest ways to solve this problem.

推荐答案

您可以提供自己的

You can provide your own AnnotationIntrospector to process old annotation.

ObjectMapper mapper = new ObjectMapper();
mapper.setAnnotationIntrospector(new MyAnnotationIntrospector());

您还可以签出杰克逊github上列出的 jackson-legacy-introspector .这是旧注释的AnnotationIntrospector的现有实现.

You can also checkout the jackson-legacy-introspector listed on the jackson github. It's an existing implementation of AnnotationIntrospector for old annotations.

这篇关于如何使更快的XML ObjectMapper与Codehaus注释一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆