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

Custom Id<*> with UUID implementation not supported (Jackson) #309

Open
rvplauborg opened this issue Dec 9, 2021 · 3 comments
Open

Custom Id<*> with UUID implementation not supported (Jackson) #309

rvplauborg opened this issue Dec 9, 2021 · 3 comments

Comments

@rvplauborg
Copy link

rvplauborg commented Dec 9, 2021

Hi,

I cannot get a proper setup working using UUID for entity ids with KMongo. Here are some relevant snippets from my setup:

abstract class DomainEntity<T : DomainEntity<T>> {
    @get:JsonProperty("_id")
    abstract val id: EntityId<T>
    ...
}

class SomeEntity(override val id: EntityId<SomeEntity>) : DomainEntity<SomeEntity>()

@JvmInline
value class EntityId<T : DomainEntity<T>>(val value: UUID) {
    init {
        validate(this) {
            validate(EntityId<T>::value).isNotEqualTo(emptyUUID)
        }
    }

    override fun toString(): String {
        return value.toString()
    }
}
KMongo.createClient(
        MongoClientSettings.builder()
            .uuidRepresentation(UuidRepresentation.STANDARD)
            .applyConnectionString(ConnectionString(mongoDBContainer.replicaSetUrl))
            .build()
    )

I can create an entity, but id is not on the specified standard representation: BinData(3, "DEvqK/vTeQUtpMdfG8LrmQ==").

But other than creating a new entity, operations such as mongoCollection.deleteOneById(clientSession, entity.id) or other operations (find etc.) fail with com.fasterxml.jackson.databind.JsonMappingException: unsupported id type 7e4e1aa4-4a53-482a-bb43-91ac7588740b (example UUID).

Am I doing it wrong or is there no support for UUID entity ids - and how come my uuidRepresentation configuration does not work (i.e. the id is still using version 3 as shown above)?

@rvplauborg rvplauborg changed the title Custom ID types not working UUID entity id type not working Dec 9, 2021
@rvplauborg rvplauborg changed the title UUID entity id type not working UUID entity id type not working (Jackson, custom ID type) Dec 11, 2021
@rvplauborg rvplauborg changed the title UUID entity id type not working (Jackson, custom ID type) UUID entity id not working (Jackson) Dec 11, 2021
@zigzago
Copy link
Member

zigzago commented Dec 19, 2021

You are right, UUID is not supported for now as id type

@jurredejongh
Copy link

The way I fixed the issue that it was still using version 3 instead of standard was by also setting the following: KMongoJacksonFeature.setUUIDRepresentation(UuidRepresentation.STANDARD)

@zigzago zigzago changed the title UUID entity id not working (Jackson) Custom Id<*> with UUID implementation not supported (Jackson) Apr 8, 2022
@zigzago
Copy link
Member

zigzago commented Apr 8, 2022

I change the title of the issue. What is not supported is Id<*> implementation with UUID (related to "unsupported id type" error message). Direct UUID _id type declaration is supported.

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

No branches or pull requests

3 participants