Details
-
Sub-task
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
Description
//CodecRegistry.java private <T> Codec<T> getCodec(Class<T> format) { final List<Class<?>> classes = new ArrayList<>(); classes.add(format); classes.addAll(ClassUtils.getAllSuperclasses(format)); classes.addAll(ClassUtils.getAllInterfaces(format)); for (Class<?> clazz : classes) { final Codec<?> codec = valueCodecs.get(clazz); if (codec != null) { return (Codec<T>) codec; } } throw new IllegalStateException( "Codec is not registered for type: " + format); }
In the code above, it tries to get a codec from the super classes and interfaces of T.
Suppose Class<T> is not in valueCodecs and Class<S> is in valueCodecs, where S is a super class/interface of T and S != T. The method will return Codec<S>. However, Codec<S> is a lossy codec:
- Codec<S> can serialize T as S, possibly losing the extra information in T but not in S;
- Codec<S> cannot deserialize T – it will return S instead.
In such cases, the returned Codec<S> does not match the return type Codec<T>.
Attachments
Issue Links
- links to