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

Understanding custom object mappers to specific jsonb column #746

Open
danielferreiradf opened this issue Oct 30, 2024 · 1 comment
Open
Labels

Comments

@danielferreiradf
Copy link

Hello. The library is great and has been very useful, but I have an use case which we need to have a different configuration to serialize the json in the second column in the same table. Based on what I found about, the library uses Jackson object mapper to do the serialization and I found this article https://vladmihalcea.com/hibernate-types-customize-jackson-objectmapper/ which was a bit difficult to follow from my side, sorry. I am not sure if this is what would support this issue? Is there a way to a pass a different object mapper class with different configuration to be used in only of the jsonb columns?

@Entity
@Table(name = "my_table")
class MyTable(
    @Id
    var id: String,
    @Type(JsonType::class)
    @Column(columnDefinition = "jsonb")
    var bookings: List<Booking>,
    @CreationTimestamp
    @Column(name = "created_at", updatable = false)
    var createdAt: LocalDateTime? = null,
    @UpdateTimestamp
    var updatedAt: LocalDateTime? = null,
     @Type(JsonType::class)
    @Column(columnDefinition = "jsonb")
    var details: List<Detail>,
)

I would happily contribute to include documentation of how to achieve this use case. Thank you.

@danielferreiradf danielferreiradf changed the title Understand custom object mappers Understanding custom object mappers to specific jsonb column Oct 30, 2024
@vladmihalcea
Copy link
Owner

@danielferreiradf The JsonType has various constructors that can help you provide a custom ObjectMapper, like the JsonType(ObjectMapper objectMapper) one.

You could extend the JsonType to provide your custom ObjectMapper from a given static context and then declare the entity attribute to use the extended JsonType.

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

No branches or pull requests

2 participants