private void test(HierarchicalStreamDriver driver) {
    XStream xstream = new XStream(driver);
    xstream.registerConverter(
        new CollectionConverter(xstream.getMapper()) {

          public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
            ExtendedHierarchicalStreamReader exReader = (ExtendedHierarchicalStreamReader) reader;
            if (exReader.peekNextChild() == null) {
              return new ArrayList();
            }
            return super.unmarshal(reader, context);
          }
        });

    SampleLists in = new SampleLists();
    in.good.add("one");
    in.good.add("two");
    in.good.add("three");
    in.bad.add(Boolean.TRUE);
    in.bad.add(Boolean.FALSE);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    xstream.toXML(in, buffer);
    Object out = xstream.fromXML(new ByteArrayInputStream(buffer.toByteArray()));

    Assert.assertEquals(in, out);
  }
示例#2
0
 public static XStream getXStream() {
   if (xStream == null) {
     synchronized (DashboardModelUtils.class) {
       if (xStream == null) {
         xStream = new XStream();
         xStream.alias("dashboard", Dashboard.class);
         xStream.alias("widget", Widget.class);
         xStream.alias("parameters", IParameters.class, Parameters.class);
         xStream.aliasAttribute(Dashboard.class, "title", "title");
         xStream.aliasAttribute(Dashboard.class, "layoutConstraints", "layoutConstraints");
         xStream.aliasAttribute(Dashboard.class, "rowConstraints", "rowConstraints");
         xStream.aliasAttribute(Dashboard.class, "colConstraints", "colConstraints");
         xStream.aliasAttribute(Widget.class, "classname", "classname");
         xStream.aliasAttribute(Widget.class, "id", "id");
         xStream.aliasAttribute(Widget.class, "style", "style");
         xStream.aliasAttribute(Widget.class, "title", "title");
         xStream.aliasAttribute(Widget.class, "collapsible", "collapsible");
         xStream.aliasAttribute(Widget.class, "collapsed", "collapsed");
         xStream.aliasAttribute(Widget.class, "hideTitleBar", "hideTitleBar");
         xStream.aliasAttribute(Widget.class, "layoutData", "layoutData");
         xStream.aliasAttribute(Widget.class, "listenToWidgets", "listenToWidgets");
         xStream.addImplicitCollection(Dashboard.class, "widgets", Widget.class);
         xStream.registerConverter(new ParametersConverter(xStream.getMapper()));
       }
     }
   }
   return xStream;
 }
示例#3
0
 public static void configure(XStream xStream) {
   xStream.registerConverter(new StringPropertyConverter(xStream.getMapper()));
   xStream.registerConverter(new BooleanPropertyConverter(xStream.getMapper()));
   xStream.registerConverter(new ObjectPropertyConverter(xStream.getMapper()));
   xStream.registerConverter(new DoublePropertyConverter(xStream.getMapper()));
   xStream.registerConverter(new LongPropertyConverter(xStream.getMapper()));
   xStream.registerConverter(new IntegerPropertyConverter(xStream.getMapper()));
   xStream.registerConverter(new ObservableListConverter(xStream.getMapper()));
 }
  @Test
  public void testName() throws Exception {
    XStream xStream = new XStream();
    xStream.registerConverter(new ToSingleValue());

    Mapper mapper = xStream.getMapper();
    ReflectionProvider reflectionProvider = xStream.getReflectionProvider();
    ConverterLookup converterLookup = xStream.getConverterLookup();
    String valueField = null;
    ToAttributedValueConverter converter =
        new ToAttributedValueConverter(
            AClass.class, mapper, reflectionProvider, converterLookup, valueField);
    xStream.registerConverter(converter);
    System.out.println(xStream.toXML(new AClass()));
  }
示例#5
0
 static {
   XSTREAM.alias("fingerprint", Fingerprint.class);
   XSTREAM.alias("range", Range.class);
   XSTREAM.alias("ranges", RangeSet.class);
   XSTREAM.registerConverter(new HexBinaryConverter(), 10);
   XSTREAM.registerConverter(
       new RangeSet.ConverterImpl(
           new CollectionConverter(XSTREAM.getMapper()) {
             @Override
             protected Object createCollection(Class type) {
               return new ArrayList();
             }
           }),
       10);
 }
 /** @return */
 private XStream initXStream(final Session session, final boolean nullifyPk) {
   final XStream xstream =
       new XStream() {
         @Override
         protected MapperWrapper wrapMapper(final MapperWrapper next) {
           return new HibernateMapper(new HibernateCollectionsMapper(next));
         }
       };
   // Converter für die Hibernate-Collections
   xstream.registerConverter(new HibernateCollectionConverter(xstream.getConverterLookup()));
   xstream.registerConverter(
       new HibernateProxyConverter(
           xstream.getMapper(), new PureJavaReflectionProvider(), xstream.getConverterLookup()),
       XStream.PRIORITY_VERY_HIGH);
   xstream.setMarshallingStrategy(
       new XStreamMarshallingStrategy(XStreamMarshallingStrategy.RELATIVE));
   init(xstream);
   return xstream;
 }