Skip to content

Commit

Permalink
Resolve UUID to ScalarPlaceholder<String>
Browse files Browse the repository at this point in the history
To be able to simply represent UUIDs, when resolving
one, a `ScalarPlaceholder` containing its string
representation is returned.
  • Loading branch information
AntonOellerer committed Oct 17, 2022
1 parent 3e16d3e commit e72966f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group 'com.docutools'
version = '1.5.7-alpha.1'
version = '1.5.8-alpha.2'

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -401,6 +402,8 @@ private Optional<PlaceholderData> resolveSimplePlaceholder(Object property, Stri
} else if (property instanceof Path path && isFieldAnnotatedWith(bean.getClass(), placeholderName, Image.class)) {
return ReflectionUtils.findFieldAnnotation(bean.getClass(), placeholderName, Image.class)
.map(image -> new ImagePlaceholderData(path).withMaxWidth(image.maxWidth()));
} else if (property instanceof UUID uuid) {
return Optional.of(new ScalarPlaceholderData<>(uuid.toString()));
} else {
return Optional.empty();
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/com/docutools/jocument/ReflectionResolvingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,14 @@ void shouldTranslateShipName() {

assertThat(shipName.get().toString(), equalTo("VSS Unternehmung"));
}

@Test
void shouldResolveUUIDtoString() {
Person picardPerson = SampleModelData.PICARD_PERSON;
var resolver = new ReflectionResolver(picardPerson);

var id = resolver.resolve("id");

assertThat(id.get().toString(), equalTo(picardPerson.getId().toString()));
}
}
6 changes: 6 additions & 0 deletions src/test/java/com/docutools/jocument/sample/model/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneOffset;
import java.util.UUID;

public class Person {
private final UUID id = UUID.randomUUID();

private final String firstName;
private final String lastName;
Expand Down Expand Up @@ -55,4 +57,8 @@ public void setFavouriteShip(Ship favouriteShip) {
public Ship getFavouriteShip() {
return favouriteShip;
}

public UUID getId() {
return id;
}
}

0 comments on commit e72966f

Please sign in to comment.