-
Notifications
You must be signed in to change notification settings - Fork 192
Document ID as UUID #1529
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
Comments
Adding a custom converter for UUID might fix this problem. I'm not sure what other problems you might run into after that. Edit: there is already a custom converter. |
I tried with a custom converter : override fun customConversions(): CustomConversions {
return CouchbaseCustomConversions(listOf(StringToUUIDConverter.INSTANCE))
}
enum class StringToUUIDConverter : Converter<String, UUID> {
INSTANCE;
override fun convert(source: String): UUID {
LoggerFactory.getLogger(StringToUUIDConverter::class.java).error("converting $source to UUID")
return UUID.fromString(source)
}
} Creating my object like this TestUUID(
UUID.fromString("fc1cc4c4-b7ea-4cb4-b43a-3fb9f574d123"),
"TEST",
UUID.fromString("fc1cc4c4-b7ea-4cb4-b43a-3fb9f574d456")
) I can see that both UUIDS are converted with my converter
Even if it goes through my converter, the id value is still a String before So should I conclude that it's not a bug and document IDs have to be a String ? |
There already are StringToUUID and UUIDToString converters in OtherConverters. (I saw that when I went to add one). But if you create a constructor with a String uuidString arg, and then in the constructor convert ...
Then you might avoid this. |
btw - if you have a field named "id", it doesn't need the @id annotation. |
Yes this is the workaround I'm doing now but using Kotlin, it makes my data class dirty whereas one of benefit of data classes (same as records) is it's simple to write without boilerplate code
I didn't know that one, thank you ! Thank you for investigating, really appreciated ! |
The issue is that the id for CouchbaseDocument is a String. I'm going to change it to Object and this should solve the problem. |
Edit: it's merged now. Will be in 4.4.3-SNAPSHOT @rbleuse - there's a branch to fix the UUID issue in 4.4.x. you can clone it, then mvn install -DskipTests, then add mavenLocal() to your build.gradle.kt. |
Hi @mikereiche, thank you for fixing this, unfortunately I still have a class cast exception with latest snapshot when reading the document I did a bit of investigation, and the conversion is not done in this method : Lines 951 to 966 in 3a4459f
I believe the conversion is usually done for any other UUID by the
So this method returns directly I experimented what could happen if I run |
I created a PR that seems to be working without regression, please check |
Hello,
quick question, the documentation is a bit confusing on that part :
In case of UUID, the
@Id
has to be a stringified UUID ?I'm asking because I tried to set a document Id as an UUID :
Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.UUID (java.lang.String and java.util.UUID are in module java.base of loader 'bootstrap')
stack trace
The text was updated successfully, but these errors were encountered: