泽西岛的系统范围适配器?
我正在尝试为 Jersey 中的 java.util.Locale
类型配置“系统范围”自定义 javax.xml.bind.annotation.adapters.XmlAdapter
。在我控制的类上使用 @XmlJavaTypeAdapter 很容易,但情况并非总是如此(我无法注释的第三方代码)。
这似乎是一个非常常见的问题,但我找不到任何好的例子或文档来说明如何处理它。
那么,有可能吗?
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我可以看到三个可能的选项:
我的建议是使用方法 1,该方法简单明了。
I can see three possible options:
My advice would be to use approach 1, which is simple and straightforward.
如果您需要注释无法修改的类,则始终可以使用 EclipseLink JAXB (MOXy) 的外部化元数据功能。
元数据文件看起来像这样:
对于 EclipseLink MOXy,您需要在模型类中添加一个 jaxb.properties 文件,其中包含以下条目:
If you need to annotate classes you can't modify, you could always use the externalized metadata feature of EclipseLink JAXB (MOXy).
The metadata file would look something like:
To you EclipseLink MOXy you need to add a jaxb.properties file in with your model classes with the following entry:
您可能还想查看用于类似目的的 JAXBIntroductions 项目。注释配置保存在文件中,无需修改源代码。通过实现 JAX-RS 提供程序,它确实可以与 Jersey 很好地配合。您可以查看我的博客条目 它通过一个例子详细解释了这一点。下面是一个简单的 JAXBContextResolver,为 JAXBIntroductions 提供,可以在 Jersey 应用程序中使用。
You may also want to look at JAXBIntroductions project which is intended for similar purpose. The annotation configuration is kept in a file, without requiring modification to source code. It does work nicely with Jersey, by implementing a JAX-RS provider. You can check out my blog entry which explains this in detail with an example. Here is a simple JAXBContextResolver provide for JAXBIntroductions that can be used in your Jersey application.