论坛首页 Java企业应用论坛

使用xStream进行java object<-->xml之间的转换

浏览 19688 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-04-13  
I find another compatible problem today.

    
    Insured insured1 = new Insured();
    insured1.setInsuredName("insured1");
    
    Insured insured2 = new Insured();
    insured2.setInsuredName("insured2");
    
    List list = new ArrayList();
    list.add(insured1);
    list.add(insured2);
    
    XStream xstream = new XStream(new DomDriver());
    xstream.alias("Form", List.class);
    String xml = xstream.toXML(list);
    System.out.println(xml);


In version 1.2
output:

<Form>
  <sojo.sample.Insured>
    <insuredName>insured1</insuredName>
  </sojo.sample.Insured>
  <sojo.sample.Insured>
    <insuredName>insured2</insuredName>
  </sojo.sample.Insured>
</Form>

In version 1.1
output:

<list>
  <sojo.sample.Insured>
    <insuredName>insured1</insuredName>
  </sojo.sample.Insured>
  <sojo.sample.Insured>
    <insuredName>insured2</insuredName>
  </sojo.sample.Insured>
</list>


So, i decide to give up using xstream in my next version project
0 请登录后投票
   发表时间:2007-04-16  
JJYAO 写道
I find another compatible problem today.

    
    Insured insured1 = new Insured();
    insured1.setInsuredName("insured1");
    
    Insured insured2 = new Insured();
    insured2.setInsuredName("insured2");
    
    List list = new ArrayList();
    list.add(insured1);
    list.add(insured2);
    
    XStream xstream = new XStream(new DomDriver());
    xstream.alias("Form", List.class);
    String xml = xstream.toXML(list);
    System.out.println(xml);


In version 1.2
output:

<Form>
  <sojo.sample.Insured>
    <insuredName>insured1</insuredName>
  </sojo.sample.Insured>
  <sojo.sample.Insured>
    <insuredName>insured2</insuredName>
  </sojo.sample.Insured>
</Form>

In version 1.1
output:

<list>
  <sojo.sample.Insured>
    <insuredName>insured1</insuredName>
  </sojo.sample.Insured>
  <sojo.sample.Insured>
    <insuredName>insured2</insuredName>
  </sojo.sample.Insured>
</list>


So, i decide to give up using xstream in my next version project


That's why you should realize inheriting from third-party util classes is really
important. I don't believe you should reject for the compatible issue.
0 请登录后投票
   发表时间:2007-04-16  
已经习惯了用JAXB了!各方面都还满意
0 请登录后投票
   发表时间:2007-04-16  
fire使用的却是xmlbean
0 请登录后投票
   发表时间:2007-06-27  
JJYAO,how to remove the reference of cglib?
0 请登录后投票
   发表时间:2007-07-11  
The same question as above to JJYAO...
How to remove the reference of cglib?

Currently I encounter an issue while converting a hibernate set property to Json(I think XML should have same problem). Could u explain the solution to us?

Thank u very much in advance.
0 请登录后投票
   发表时间:2007-07-12  
支持xStream,一直用它!好使!!
0 请登录后投票
   发表时间:2007-07-12  
david3d 写道
The same question as above to JJYAO...
How to remove the reference of cglib?

Currently I encounter an issue while converting a hibernate set property to Json(I think XML should have same problem). Could u explain the solution to us?

Thank u very much in advance.


Version: xstream 1.2.1
To make comments on XStream.java from line 635 to 640, then re-compile 


//        if (jvm.loadClass("net.sf.cglib.proxy.Enhancer") != null) {
//            dynamicallyRegisterConverter(
//                    "com.thoughtworks.xstream.converters.reflection.CGLIBEnhancedConverter",
//                    PRIORITY_NORMAL, new Class[]{Mapper.class, ReflectionProvider.class}, 
//                    new Object[]{mapper, reflectionProvider});
//        }
0 请登录后投票
   发表时间:2007-07-16  
Thanks. JJYAO.
I have replied you several days before but it was deleted by forum manager. Maybe because I pasted some redundant code lines in that reply : (

Your solution still cannot resolve my problem. But give me a good directive. I will try another way. Thanks again
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics