Examples of DuplicateFieldException


Examples of com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.DuplicateFieldException

                        throw exception;
                    }

                    reflectionProvider.writeField(result, fieldName, value, declaringClass);
                    if (!seenFields.add(new FastField(declaringClass, fieldName))) {
                        throw new DuplicateFieldException(fieldName + " [" + declaringClass.getName() + "]");
                    }
                }
            }
        }

        if (valueField != null) {
            final Class<?> classDefiningField = valueField.getDeclaringClass();
            final String fieldName = valueField.getName();
            final Field field = fieldName == null ? null : reflectionProvider.getField(classDefiningField, fieldName);
            if (fieldName == null || field == null) {
                final ConversionException exception = new ConversionException("Cannot assign value to field of type");
                exception.add("element", reader.getNodeName());
                exception.add("field", fieldName);
                exception.add("target type", context.getRequiredType().getName());
                throw exception;
            }

            Class<?> type;
            final String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper);
            if (classAttribute != null) {
                type = mapper.realClass(classAttribute);
            } else {
                type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(result, fieldName,
                    classDefiningField));
            }

            final Object value = context.convertAnother(result, type, mapper.getLocalConverter(field
                .getDeclaringClass(), field.getName()));

            final Class<?> definedType = reflectionProvider.getFieldType(result, fieldName, classDefiningField);
            if (!definedType.isPrimitive()) {
                type = definedType;
            }

            if (value != null && !type.isAssignableFrom(value.getClass())) {
                final ConversionException exception = new ConversionException("Cannot assign object to type");
                exception.add("object type", value.getClass().getName());
                exception.add("target type", type.getName());
                throw exception;
            }

            reflectionProvider.writeField(result, fieldName, value, classDefiningField);
            if (!seenFields.add(new FastField(classDefiningField, fieldName))) {
                throw new DuplicateFieldException(fieldName + " [" + classDefiningField.getName() + "]");
            }
        }
        return result;
    }
View Full Code Here

Examples of com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.DuplicateFieldException

                        throw exception;
                    }

                    reflectionProvider.writeField(result, fieldName, value, declaringClass);
                    if (!seenFields.add(new FastField(declaringClass, fieldName))) {
                        throw new DuplicateFieldException(fieldName
                            + " ["
                            + declaringClass.getName()
                            + "]");
                    }
                }
            }
        }

        if (valueField != null) {
            final Class classDefiningField = valueField.getDeclaringClass();
            final String fieldName = valueField.getName();
            if (fieldName == null
                || !reflectionProvider.fieldDefinedInClass(fieldName, resultType)) {
                final ConversionException exception = new ConversionException(
                    "Cannot assign value to field of type");
                exception.add("element", reader.getNodeName());
                exception.add("field", fieldName);
                exception.add("target type", context.getRequiredType().getName());
                throw exception;
            }

            Class type;
            final String classAttribute = HierarchicalStreams
                .readClassAttribute(reader, mapper);
            if (classAttribute != null) {
                type = mapper.realClass(classAttribute);
            } else {
                type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(
                    result, fieldName, classDefiningField));
            }

            final Field field = reflectionProvider.getField(classDefiningField, fieldName);
            final Object value = context.convertAnother(
                result, type,
                mapper.getLocalConverter(field.getDeclaringClass(), field.getName()));

            final Class definedType = reflectionProvider.getFieldType(
                result, fieldName, classDefiningField);
            if (!definedType.isPrimitive()) {
                type = definedType;
            }

            if (value != null && !type.isAssignableFrom(value.getClass())) {
                final ConversionException exception = new ConversionException(
                    "Cannot assign object to type");
                exception.add("object type", value.getClass().getName());
                exception.add("target type", type.getName());
                throw exception;
            }

            reflectionProvider.writeField(result, fieldName, value, classDefiningField);
            if (!seenFields.add(new FastField(classDefiningField, fieldName))) {
                throw new DuplicateFieldException(fieldName
                    + " ["
                    + classDefiningField.getName()
                    + "]");
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.