|
18 | 18 | import org.bson.codecs.Codec; |
19 | 19 | import org.bson.codecs.configuration.CodecProvider; |
20 | 20 | import org.bson.codecs.configuration.CodecRegistry; |
| 21 | +import org.bson.diagnostics.Logger; |
| 22 | +import org.bson.diagnostics.Loggers; |
21 | 23 |
|
22 | 24 | import java.util.ArrayList; |
23 | 25 | import java.util.Collections; |
|
27 | 29 | import java.util.Map; |
28 | 30 | import java.util.Set; |
29 | 31 |
|
| 32 | +import static java.lang.String.format; |
30 | 33 | import static java.util.Arrays.asList; |
31 | 34 | import static org.bson.assertions.Assertions.notNull; |
32 | 35 |
|
|
36 | 39 | * @since 3.5 |
37 | 40 | */ |
38 | 41 | public final class PojoCodecProvider implements CodecProvider { |
| 42 | + static final Logger LOGGER = Loggers.getLogger("codecs.pojo"); |
39 | 43 | private final boolean automatic; |
40 | 44 | private final Map<Class<?>, ClassModel<?>> classModels; |
41 | 45 | private final Set<String> packages; |
@@ -76,14 +80,15 @@ private <T> PojoCodec<T> getPojoCodec(final Class<T> clazz, final CodecRegistry |
76 | 80 | } else if (automatic || (clazz.getPackage() != null && packages.contains(clazz.getPackage().getName()))) { |
77 | 81 | try { |
78 | 82 | classModel = createClassModel(clazz, conventions); |
79 | | - } catch (IllegalStateException e) { |
80 | | - return null; |
81 | | - } |
82 | | - if (!clazz.isInterface() && classModel.getPropertyModels().isEmpty()) { |
| 83 | + if (!clazz.isInterface() && classModel.getPropertyModels().isEmpty()) { |
| 84 | + return null; |
| 85 | + } |
| 86 | + discriminatorLookup.addClassModel(classModel); |
| 87 | + return new AutomaticPojoCodec<T>(new PojoCodecImpl<T>(classModel, registry, propertyCodecProviders, discriminatorLookup)); |
| 88 | + } catch (Exception e) { |
| 89 | + LOGGER.warn(format("Cannot use '%s' with the PojoCodec.", clazz.getSimpleName()), e); |
83 | 90 | return null; |
84 | 91 | } |
85 | | - discriminatorLookup.addClassModel(classModel); |
86 | | - return new AutomaticPojoCodec<T>(new PojoCodecImpl<T>(classModel, registry, propertyCodecProviders, discriminatorLookup)); |
87 | 92 | } |
88 | 93 | return null; |
89 | 94 | } |
|
0 commit comments