Package com.thoughtworks.xstream.converters

Examples of com.thoughtworks.xstream.converters.ConversionException


    protected Object createCollection(final Class<?> type) {
        final Class<?> defaultType = mapper().defaultImplementationOf(type);
        try {
            return defaultType.newInstance();
        } catch (final InstantiationException e) {
            throw new ConversionException("Cannot instantiate " + defaultType.getName(), e);
        } catch (final IllegalAccessException e) {
            throw new ConversionException("Cannot instantiate " + defaultType.getName(), e);
        }
    }
View Full Code Here


                return calendar;
            } catch (final IllegalArgumentException e) {
                // try with next formatter
            }
        }
        throw new ConversionException("Cannot parse date " + str);
    }
View Full Code Here

    @Override
    public Object fromString(final String str) {
        try {
            return UUID.fromString(str);
        } catch (final IllegalArgumentException e) {
            throw new ConversionException("Cannot create UUID instance", e);
        }
    }
View Full Code Here

        if (conv == null) {
            final Converter converter = lookup.lookupConverterForType(type);
            if (converter instanceof SingleValueConverter) {
                conv = (SingleValueConverter)converter;
            } else {
                throw new ConversionException("No SingleValueConverter for key available");
            }
        }
        return conv;
    }
View Full Code Here

            } catch (final ParseException e3) {
                // no worries, let's try the next format.
            }
        }
        // no dateFormats left to try
        throw new ConversionException("Cannot parse date " + str);
    }
View Full Code Here

    @Override
    public Object fromString(final String str) {
        final int idx = str.lastIndexOf('.');
        if (idx < 0 || str.length() - idx < 2 || str.length() - idx > 10) {
            throw new ConversionException("Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]");
        }
        try {
            final Timestamp timestamp = new Timestamp(format.parse(str.substring(0, idx)).getTime());
            final StringBuilder buffer = new StringBuilder(str.substring(idx + 1));
            while (buffer.length() != 9) {
                buffer.append('0');
            }
            timestamp.setNanos(Integer.parseInt(buffer.toString()));
            return timestamp;
        } catch (final NumberFormatException e) {
            throw new ConversionException("Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]", e);
        } catch (final ParseException e) {
            throw new ConversionException("Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]");
        }
    }
View Full Code Here

                return declaringClass.getDeclaredMethod(methodName, parameterTypes);
            } else {
                return declaringClass.getDeclaredConstructor(parameterTypes);
            }
        } catch (final NoSuchMethodException e) {
            throw new ConversionException(e);
        }
    }
View Full Code Here

    @Override
    public Object fromString(final String str) {
        try {
            return new URL(str);
        } catch (final MalformedURLException e) {
            throw new ConversionException(e);
        }
    }
View Full Code Here

        }

        @Override
        public int accept(final Method method) {
            if (!callbackIndexMap.containsKey(method)) {
                final ConversionException exception = new ConversionException(
                    "CGLIB callback not detected in reverse engineering");
                exception.add("CGLIB callback", method.toString());
                throw exception;
            }
            return callbackIndexMap.get(method).intValue();
        }
View Full Code Here

                final SingleValueConverter converter = mapper.getConverterFromItemType(fieldName, type, definedIn);
                if (converter != null) {
                    final String attribute = mapper.aliasForAttribute(mapper.serializedMember(definedIn, fieldName));
                    if (value != null) {
                        if (writtenAttributes.contains(fieldName)) { // TODO: use attribute
                            throw new ConversionException("Cannot write field with name '"
                                + fieldName
                                + "' twice as attribute for object of type "
                                + source.getClass().getName());
                        }
                        final String str = converter.toString(value);
View Full Code Here

TOP

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

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.