Closed Silthus closed 2 years ago
My memory was a little rusty but thanks to your example project I was able to figure this out again quickly. In the cases where inheritance occurs, intended serialization type shall be provided via SerializationData typed methods.
Replace:
data.add("text", object.getText());
With:
data.add("text", object.getText(), Component.class);
Also take a look for other typed methods, for collections, maps, etc.: https://github.com/OkaeriPoland/okaeri-configs/blob/master/core/src/main/java/eu/okaeri/configs/serdes/SerializationData.java
Note third section of typed add method:
/**
* Adds value to the serialization data under specific key.
* Provided value is simplified using attached Configurer.
* <p>
* This method allows to narrow target simplification type
* and is recommended to be used with non-primitive classes.
* <p>
* Specifying target simplification type allows to make sure
* correct serializer is used, e.g. interface type instead
* of some implementation type that would otherwise inferred.
*
* @param key target key
* @param value target value
* @param valueType type of value for simplification process
* @param <T> type of value
*/
public <T> void add(@NonNull String key, Object value, @NonNull Class<T> valueType) {
GenericsDeclaration genericType = GenericsDeclaration.of(valueType);
this.add(key, value, genericType);
}
Describe the bug I have the following config and want to use the already registered serializer for the message text of the object:
To Reproduce See the following repository with a failing test: https://github.com/sVoxelDev/okaeri-nested-serialization-bug
Expected behavior The serializers should leverage already existing serializers.