Closed allantodd closed 3 months ago
Thanks, sorry I didn't get time to reply sooner.
Here's a more complete example of how we're using Any
to store arbitrary nested metadata as JSON in Postgres. The problem is that basically Kotlin calls Object
Any
and it was missed in the mappings.
@Convert(converter = MetadataConverter::class)
@Column(columnDefinition = "jsonb")
var metadata: Map<String, Any> = mutableMapOf()
where the converter is
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import jakarta.persistence.AttributeConverter
class MetadataConverter : AttributeConverter<Map<String, Any>, String> {
private val objectMapper = jacksonObjectMapper()
override fun convertToDatabaseColumn(attribute: Map<String, Any>?): String {
return objectMapper.writeValueAsString(attribute ?: emptyMap<String, Any>())
}
override fun convertToEntityAttribute(dbData: String?): Map<String, Any> {
return objectMapper.readValue(dbData ?: "{}")
}
}
Well, if you keen, please update the example https://github.com/OpenFeign/querydsl/tree/master/querydsl-examples/querydsl-example-kotlin-codegen
All good if you can't, but amazing if you could
Ah, hadn't seen that module. Okay will take a look. Thanks
The code generator uses
Object
instead ofAny
resulting in compiler warnings as described at https://github.com/querydsl/querydsl/issues/3740