|
16 | 16 |
|
17 | 17 | package org.bson.codecs.pojo; |
18 | 18 |
|
19 | | -import org.bson.codecs.configuration.CodecConfigurationException; |
20 | | - |
21 | 19 | import java.lang.annotation.Annotation; |
22 | 20 | import java.lang.reflect.Constructor; |
23 | 21 | import java.lang.reflect.Field; |
|
38 | 36 | import static java.util.Arrays.asList; |
39 | 37 | import static java.util.Collections.reverse; |
40 | 38 | import static org.bson.assertions.Assertions.notNull; |
41 | | -import static org.bson.codecs.pojo.PropertyReflectionUtils.isGetter; |
42 | 39 | import static org.bson.codecs.pojo.PropertyReflectionUtils.getPropertyMethods; |
| 40 | +import static org.bson.codecs.pojo.PropertyReflectionUtils.isGetter; |
43 | 41 | import static org.bson.codecs.pojo.PropertyReflectionUtils.toPropertyName; |
44 | 42 |
|
45 | 43 | final class PojoBuilderHelper { |
| 44 | + |
46 | 45 | @SuppressWarnings("unchecked") |
47 | 46 | static <T> void configureClassModelBuilder(final ClassModelBuilder<T> classModelBuilder, final Class<T> clazz) { |
48 | 47 | classModelBuilder.type(notNull("clazz", clazz)); |
@@ -158,11 +157,10 @@ private static <T, S> PropertyMetadata<T> getOrCreateMethodPropertyMetadata(fina |
158 | 157 | final Type genericType) { |
159 | 158 | PropertyMetadata<T> propertyMetadata = getOrCreatePropertyMetadata(propertyName, declaringClassName, propertyNameMap, typeData); |
160 | 159 | if (!isAssignableClass(propertyMetadata.getTypeData().getType(), typeData.getType())) { |
161 | | - throw new CodecConfigurationException(format("Property '%s' in %s, has differing data types: %s and %s", propertyName, |
| 160 | + propertyMetadata.setError(format("Property '%s' in %s, has differing data types: %s and %s.", propertyName, |
162 | 161 | declaringClassName, propertyMetadata.getTypeData(), typeData)); |
163 | 162 | } |
164 | | - cachePropertyTypeData(propertyMetadata, propertyTypeParameterMap, parentClassTypeData, genericTypeNames, |
165 | | - genericType); |
| 163 | + cachePropertyTypeData(propertyMetadata, propertyTypeParameterMap, parentClassTypeData, genericTypeNames, genericType); |
166 | 164 | return propertyMetadata; |
167 | 165 | } |
168 | 166 |
|
@@ -223,7 +221,8 @@ static <T> PropertyModelBuilder<T> createPropertyModelBuilder(final PropertyMeta |
223 | 221 | .readAnnotations(propertyMetadata.getReadAnnotations()) |
224 | 222 | .writeAnnotations(propertyMetadata.getWriteAnnotations()) |
225 | 223 | .propertySerialization(new PropertyModelSerializationImpl<T>()) |
226 | | - .propertyAccessor(new PropertyAccessorImpl<T>(propertyMetadata)); |
| 224 | + .propertyAccessor(new PropertyAccessorImpl<T>(propertyMetadata)) |
| 225 | + .setError(propertyMetadata.getError()); |
227 | 226 |
|
228 | 227 | if (propertyMetadata.getTypeParameters() != null) { |
229 | 228 | specializePropertyModelBuilder(propertyModelBuilder, propertyMetadata); |
|
0 commit comments