Jaxb:在不修改JAXB java类的情况下追加Request XML的字段 [英] Jaxb : Append field of Request XML without modfying JAXB java class

查看:98
本文介绍了Jaxb:在不修改JAXB java类的情况下追加Request XML的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JAXB 2.0进行使用RestFul Webservices的Application Deveopment。
现在请求中有一个修改,即我将在请求XML中获得另一个字段/变量。

I am using JAXB 2.0 for the Application Deveopment which is using RestFul Webservices . Now there is a modification in the request , that is i will be getting another filed/variable in the request XML .

<Root Id="567" att="758" />   

修改后的请求将

 <Root Id="567" att="758" anotherfiledadded ="kiran" />   

我的问题是,是否可以在UserData类中自动附加该字段(anotherfiledadded)(无修改UserData ??)

My question is , is it possible to automatically append that field (anotherfiledadded)in the UserData class (Without modifying the UserData ??)

以下是我的UserData类

@XmlRootElement(name = "Root")
@XmlAccessorType(XmlAccessType.FIELD)

public class UserData {

    @XmlAttribute
    private String Id;

    @XmlAttribute
    private String att;

// getters and setters 


推荐答案

您可以尝试在运行时使用 javassist 。但是......看起来您还需要添加注释 @XmlAttribute ,我不知道 javassist 是否允许您添加注释...无论如何都要给它试试。

You can try adding the field at runtime with javassist. But... It looks like you would also require to add the Annotation @XmlAttribute and I don't know if javassist allows you to add annotations... Anyways give it a try.

参见: Javassist Add

这篇关于Jaxb:在不修改JAXB java类的情况下追加Request XML的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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