Closed
Description
This is a document in collection, exported via MongoDB Compass:
{
"_id": {
"$numberLong": "24"
},
"name": "attr",
"storageFormat": {
"elementFormat": {
"elementFormat": {
"elementFormat": {
"datatype": "DOUBLE",
"_class": "com.company.cms.persistence.entity.StorageFormatEntity$DataTypeEntity"
},
"_class": "com.company.cms.persistence.entity.StorageFormatEntity$ArrayFormatEntity"
},
"_class": "com.company.cms.persistence.entity.StorageFormatEntity$ArrayFormatEntity"
},
"_class": "com.company.cms.persistence.entity.StorageFormatEntity$ArrayFormatEntity"
},
"_class": "com.company.cms.persistence.entity.AttributeEntity"
}
At this point, everything looks correct. However, when I read it, storageFormat.elementFormat
is null.
This is the class:
public sealed interface StorageFormatEntity {
record DataTypeEntity(String datatype) implements StorageFormatEntity {}
record ContentRefEntity(List<Long> templates) implements StorageFormatEntity {}
record ArrayFormatEntity(StorageFormatEntity elementFormat) implements StorageFormatEntity {}
}
I have temporarily solved this by registering a custom read converter, but I feel like this shouldn't be necessary. I feel like this is a bug in the framework.
I am using Spring Boot 3.2.1.