You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The fix is to flush the converter into the lookup cache immediately after registration... as I found with the following code:
voidregisterConverter(MapperFactoryfactory, Type<A> aType, Type<B> bType, ...) {
CustomConverterconverter = newCustomConverter() { ... };
ConverterFactoryconverterFactory = factory.getConverterFactory();
converterFactory.registerConverter(converter);
// flush converter into cacheconverterFactory.getConverter(aType, bType);
converterFactory.getConverter(bType, aType); // only because my converter is bidirectional
}
Note: it will be necessary to do the cache fill externally to registerConverter(...) since the pairs of types that getConverter() resolves to the new converter are dependent on the result of the canConvert() method.
Looking into this more, it seems it's a workaround for the following equals and hashCode implementation in CustomConverter which is based on the class. (remove this code please?)
...the issue is that anonymous classes all have the same "class" object but different bound variables, so the processing of the converters in the DefaultConverterFactory through a LinkedHashSet will end up overwriting all but the last one registered!
The fix is to flush the converter into the lookup cache immediately after registration... as I found with the following code:
Note: it will be necessary to do the cache fill externally to
registerConverter(...)
since the pairs of types thatgetConverter()
resolves to the new converter are dependent on the result of thecanConvert()
method.Looking into this more, it seems it's a workaround for the following equals and hashCode implementation in CustomConverter which is based on the class. (remove this code please?)
orika/core/src/main/java/ma/glasnost/orika/CustomConverter.java
Lines 108 to 114 in 9f46000
...the issue is that anonymous classes all have the same "class" object but different bound variables, so the processing of the converters in the
DefaultConverterFactory
through aLinkedHashSet
will end up overwriting all but the last one registered!orika/core/src/main/java/ma/glasnost/orika/converter/DefaultConverterFactory.java
Lines 75 to 80 in 9f46000
It looks like this was first reported in 2017. Let's get this fixed?
The text was updated successfully, but these errors were encountered: