Package com.thoughtworks.xstream.converters

Examples of com.thoughtworks.xstream.converters.Converter


  @Test
  public void shouldUseTheDefaultConverterForTypesThatAreNotHypermediaAware() {
    RestfulSerialization serialization = new RestfulSerialization(null, null, null, null, null, XStreamBuilderImpl.cleanInstance());
    XStream xstream = serialization.getXStream();
    Converter converter = xstream.getConverterLookup().lookupConverterForType(CustomNonHMType.class);
    assertThat(converter.getClass(), is(typeCompatibleWith(ReflectionConverter.class)));
  }
View Full Code Here


        xStream.registerConverter(new MegaConverter());
        return xStream;
      }
    };
    XStream xstream = serialization.getXStream();
    Converter converter = xstream.getConverterLookup().lookupConverterForType(CustomType.class);
    assertThat(converter.getClass(), is(typeCompatibleWith(MegaConverter.class)));
    converter = xstream.getConverterLookup().lookupConverterForType(CustomNonHMType.class);
    assertThat(converter.getClass(), is(typeCompatibleWith(MegaConverter.class)));
  }
View Full Code Here

            }

            if (this.converters != null) {
                for (String name : this.converters) {
                    Class<Converter> converterClass = resolver.resolveMandatoryClass(name, Converter.class);
                    Converter converter;

                    Constructor<Converter> con = null;
                    try {
                        con = converterClass.getDeclaredConstructor(new Class[] {XStream.class});
                    } catch (Exception e) {
View Full Code Here

    excludes.clear();
    return this;
  }

  private void registerProxyInitializer() {
    xstream.registerConverter(new Converter() {

      @SuppressWarnings("unchecked")
      public boolean canConvert(Class clazz) {
        return initializer.isProxy(clazz);
      }

      public Object unmarshal(HierarchicalStreamReader reader,
          UnmarshallingContext context) {
        throw new AssertionError();
      }

      public void marshal(Object value, HierarchicalStreamWriter writer,
          MarshallingContext context) {
        Converter converter = xstream.getConverterLookup().lookupConverterForType(initializer.getActualClass(value));
        initializer.initialize(value);
        converter.marshal(value, writer, context);
      }
    });
  }
View Full Code Here

        if (this.params != null) {
            String xml = (String) this.params.getValue(execution);
            if (xml != null) {
                XStream xs = new XStream();
                xs.alias("map", java.util.Map.class);
                xs.registerConverter(new Converter() {
                    public boolean canConvert(Class clazz) {
                        return AbstractMap.class.isAssignableFrom(clazz);
                    }

                    public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
View Full Code Here

      if (isSimplifyingXML()) {
        xstream.omitField(AbstractConnectedContained.class, "links");
      }

      // handle styled text correctly
      xstream.registerConverter(new Converter() {

        public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
          return type.equals(StyledText.class);
        }

        public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
          StyledText st = (StyledText) source;
          if (st.getStyle() != null) {
            writer.addAttribute("style", st.getStyle());
          }
          writer.setValue(st.getText());
        }

        public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
          String style = reader.getAttribute("style");
          String text = reader.getValue();
          return new StyledText(text, style);
        }
      });

      // this makes it so that if the type is not specified in the xml, we
      // assume a string.
      xstream.registerConverter(new StringConverter() {

        @Override
        public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
          return super.canConvert(type) || type.equals(Object.class);
        }

      }, 10);

      // this compacts the representation of a hint map, which is
      // otherwise excessive
      xstream.registerConverter(new Converter() {

        public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
          HintMap map = (HintMap) source;
          for (Iterator<Entry<String, Float>> iterator = map.entrySet().iterator(); iterator.hasNext();) {
            Entry<String, Float> entry = iterator.next();
View Full Code Here

    excludes.clear();
    return this;
  }

  private void registerProxyInitializer() {
    xstream.registerConverter(new Converter() {

      public boolean canConvert(Class clazz) {
        return initializer.isProxy(clazz);
      }

      public Object unmarshal(HierarchicalStreamReader reader,
          UnmarshallingContext context) {
        throw new AssertionError();
      }

      public void marshal(Object value, HierarchicalStreamWriter writer,
          MarshallingContext context) {
        Converter converter = xstream.getConverterLookup().lookupConverterForType(initializer.getActualClass(value));
        initializer.initialize(value);
        converter.marshal(value, writer, context);
      }
    });
  }
View Full Code Here

    throw new AssertionError();
  }

  public void marshal(Object value, HierarchicalStreamWriter writer,
      MarshallingContext context) {
    Converter converter = xstream.getConverterLookup().lookupConverterForType(initializer.getActualClass(value));
    initializer.initialize(value);
    converter.marshal(value, writer, context);
  }
View Full Code Here

            }

            if (this.converters != null) {
                for (String name : this.converters) {
                    Class<Converter> converterClass = resolver.resolveMandatoryClass(name, Converter.class);
                    Converter converter;

                    Constructor con = null;
                    try {
                        con = converterClass.getDeclaredConstructor(new Class[] {XStream.class});
                    } catch (Exception e) {
View Full Code Here

                writer.startNode(name);
                context.convertAnother(item);
                writer.endNode();
            }
        });
        xstream.registerConverter(new Converter() {

            public boolean canConvert(Class type) {
                return Script.class.isAssignableFrom(type);
            }
View Full Code Here

TOP

Related Classes of com.thoughtworks.xstream.converters.Converter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.