Package com.thoughtworks.xstream.converters

Examples of com.thoughtworks.xstream.converters.Converter


            }
        }
    }

    private Converter cacheConverter(final Class<? extends ConverterMatcher> converterType) {
        Converter converter = converterCache.get(converterType);
        if (converter == null) {
            try {
                if (SingleValueConverter.class.isAssignableFrom(converterType)) {
                    final SingleValueConverter svc = (SingleValueConverter)DependencyInjectionFactory
                        .newInstance(converterType, arguments);
View Full Code Here


     */
    public DefaultConverterLookup(ClassMapper classMapper) {
    }

    public Converter lookupConverterForType(Class type) {
        Converter cachedConverter = (Converter) typeToConverterMap.get(type);
        if (cachedConverter != null) return cachedConverter;
        Iterator iterator = converters.iterator();
        while (iterator.hasNext()) {
            Converter converter = (Converter) iterator.next();
            if (converter.canConvert(type)) {
                typeToConverterMap.put(type, converter);
                return converter;
            }
        }
        throw new ConversionException("No converter specified for " + type);
View Full Code Here

        int idx = key.indexOf('@');
        if (idx < 0) {
            throw new StreamException("Not a valid key: " + key);
        }
        Class type = getMapper().realClass(key.substring(0, idx));
        Converter converter = getConverterLookup().lookupConverterForType(type);
        if (converter instanceof SingleValueConverter) {
            final SingleValueConverter svConverter = (SingleValueConverter)converter;
            return svConverter.fromString(key.substring(idx + 1));
        } else {
            throw new StreamException("No SingleValueConverter for type "
View Full Code Here

    protected String getName(final Object key) {
        if (key == null) {
            return "null@null.xml";
        }
        Class type = key.getClass();
        Converter converter = getConverterLookup().lookupConverterForType(type);
        if (converter instanceof SingleValueConverter) {
            final SingleValueConverter svConverter = (SingleValueConverter)converter;
            return getMapper().serializedClass(type)
                + '@'
                + escape(svConverter.toString(key))
View Full Code Here

    public void addAttributeFor(final Class type) {
        typeSet.add(type);
    }

    private SingleValueConverter getLocalConverterFromItemType(Class type) {
        Converter converter = converterLookup.lookupConverterForType(type);
        if (converter != null && converter instanceof SingleValueConverter) {
            return (SingleValueConverter)converter;
        } else {
            return null;
        }
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

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

  @Test
  public void shouldUseTheDefaultConverterForTypesThatAreNotHypermediaAware() {
    RestfulSerializationJSON serialization = new RestfulSerializationJSON(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

  @Test
  public void shouldReturnAnXStreamInstanceWithSupportToLinkConvertersBasedOnReflection() {
    RestfulSerialization serialization = new RestfulSerialization(null, null, null, null, null, XStreamBuilderImpl.cleanInstance());
    XStream xstream = serialization.getXStream();
    Converter converter = xstream.getConverterLookup().lookupConverterForType(CustomType.class);
    assertThat(converter.getClass(), is(typeCompatibleWith(LinkConverter.class)));
  }
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.