Skip to content

Allow Id other than String. #1535

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

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
* @author Geoffrey Mina
* @author Mark Paluch
* @author Michael Reiche
* @author Remi Bleuse
*/
public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implements ApplicationContextAware {

Expand Down Expand Up @@ -962,7 +963,7 @@ public <R> R getPropertyValue(final CouchbasePersistentProperty property) {
Object value = expression != null ? evaluator.evaluate(expression) : source.get(property.getFieldName());

if (property == entity.getIdProperty() && parent == null) {
return (R) source.getId();
return readValue(source.getId(), property.getTypeInformation(), source);
}
if (value == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,25 @@ void writesAndReadsDates() {
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();
Expand Down Expand Up @@ -946,6 +965,16 @@ public DateEntity(Date created, Calendar modified, LocalDateTime deleted) {
}
}

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 {
Expand Down