Allow document ID to be other than String (#1534)

* fixes #1529

* add author
This commit is contained in:
Rémi Bleuse
2022-08-09 02:05:29 +09:00
committed by GitHub
parent 48742b145d
commit a2a48caf79
2 changed files with 31 additions and 1 deletions

View File

@@ -686,6 +686,25 @@ public class MappingCouchbaseConverterTests {
assertThat(read.deleted.truncatedTo(ChronoUnit.MILLIS)).isEqualTo(deleted.truncatedTo(ChronoUnit.MILLIS));
}
@Test
void writesAndReadsIdAsUUID() {
String idAsString = "fc1cc4c4-b7ea-4cb4-b43a-3fb9f574d123";
UUID id = UUID.fromString(idAsString);
String otherAsString = "fc1cc4c4-b7ea-4cb4-b43a-3fb9f574d456";
UUID other = UUID.fromString(otherAsString);
UuidIdEntity entity = new UuidIdEntity(id, other);
CouchbaseDocument converted = new CouchbaseDocument();
converter.write(entity, converted);
assertThat(converted.getContent().get("other")).isEqualTo(otherAsString);
assertThat(converted.getId()).isEqualTo(idAsString);
UuidIdEntity read = converter.read(UuidIdEntity.class, converted);
assertThat(read.id).isEqualTo(id);
assertThat(read.other).isEqualTo(other);
}
@Test
void writesAndReadsNestedClass() {
CouchbaseDocument converted = new CouchbaseDocument();
@@ -946,6 +965,16 @@ public class MappingCouchbaseConverterTests {
}
}
static class UuidIdEntity {
@Id private UUID id;
private UUID other;
public UuidIdEntity(UUID id, UUID other) {
this.id = id;
this.other = other;
}
}
@Test
void idNotGenerated() {
class Entity {