Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: map Java Object to Kotlin Any #511

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

allantodd
Copy link
Contributor

The code generator uses Object instead of Any resulting in compiler warnings as described at querydsl/querydsl#3740

Copy link
Member

@velo velo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for you contribution.

The failed test is related to SQLServer being a bit fragile at the moment, I'm rerunning it, should pass.

Are you able to update the example to include Any usage?

Cheers

@velo velo merged commit 061eea2 into OpenFeign:master Jul 31, 2024
3 checks passed
@allantodd
Copy link
Contributor Author

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 ?: "{}")
    }
}

@velo
Copy link
Member

velo commented Jul 31, 2024

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

@allantodd
Copy link
Contributor Author

Ah, hadn't seen that module. Okay will take a look. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants