regarding polymorphism: is there a way to rename t...
# serialization
b
regarding polymorphism: is there a way to rename the type property? I've got a "productType" enum/string property and it should instantiate the correct class based on that property Edit: there was a link in there leading to JsonClassDiscriminator
✅ 1
c
I did try the JsonClassDiscriminator annotation and sadly notice it's work fine, but one way only (decoding). When it's time to 'encode' a json string into your data class, if one of its properties is the one you put into 'JsoClassDiscriminator' (which is very likely to be) the encode will fail Personally I had write my own serializable to be able to both decode/encode
b
oh, got that working in serialization as well
in fact I haven't tried decode yet
c
If you wanna use the annotation and have both encode/decode working, you have to annotate the property on your data class used in 'JsonClassDiscriminator' with another annotation: 'Transient'. This will force you to specify a default value, which should be what is actually in your json (and by design would always be that value)