When save document that have a property Class<?> catch exception CodecConfigurationException: Can't find a codec for CodecCacheKey{clazz=class java.lang.Class, types=null}
@Document("my_document")
public class MyDocument {
@Id
private String id;
@Field("jPt")
private JobParameter<?> jobParameter;
}
public class JobParameter<T> implements Serializable {
private T value;
private Class<T> type;
private boolean identifying;
}
Trying added Converter<JobParameter, Document> but it doesn't has effect
@Bean
public MongoCustomConversions customConversions(List<Converter<?, ?>> foreignConverters) {
List<Converter<?, ?>> converters = new ArrayList<>(List.of(
JSR310DateConverters.ZonedDateTimeToDateConverter.INSTANCE,
JSR310DateConverters.DateToZonedDateTimeConverter.INSTANCE,
JSR310DateConverters.LongToDurationConverter.INSTANCE,
JSR310DateConverters.DurationToLongConverter.INSTANCE,
**new JobParameterMongoConverter()**
));
converters.addAll(foreignConverters);
MongoCustomConversions mongoCustomConversions = new MongoCustomConversions(converters);
MongoCustomConversions.create(adapter -> adapter.useNativeDriverJavaTimeCodecs()
.registerConverters(converters));
return mongoCustomConversions;
I was not using the correct annotation on the converter. I used @ReadingConverter instead of @WritingConverter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With