diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 3cf945fe..f24609f7 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -64,7 +64,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - name: Install libvips - run: sudo apt-get install -y libvips42 + run: sudo apt-get update && sudo apt-get install -y libvips42 - name: Checkout uses: actions/checkout@v3 - name: Setup Java diff --git a/build.gradle b/build.gradle index b7acb0e9..860ee951 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ plugins { } group 'com.docutools' -version = '1.5.11' +version = '1.5.12' sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 diff --git a/src/main/java/com/docutools/jocument/impl/ReflectionResolver.java b/src/main/java/com/docutools/jocument/impl/ReflectionResolver.java index 58e77f63..d267c20e 100644 --- a/src/main/java/com/docutools/jocument/impl/ReflectionResolver.java +++ b/src/main/java/com/docutools/jocument/impl/ReflectionResolver.java @@ -333,8 +333,7 @@ private Optional doReflectiveResolve(String placeholderName, Lo } var wrappedProperty = getBeanProperty(placeholderName); if (wrappedProperty.isEmpty()) { - logger.debug("Placeholder {} could not be translated into a property", placeholderName); - return Optional.empty(); + return Optional.of(new ScalarPlaceholderData<>(null)); } var property = resolveNonFinalValue(wrappedProperty.get(), placeholderName); var simplePlaceholder = resolveSimplePlaceholder(property, placeholderName, locale, options); diff --git a/src/main/java/com/docutools/jocument/impl/ScalarPlaceholderData.java b/src/main/java/com/docutools/jocument/impl/ScalarPlaceholderData.java index d078bad5..bc791b9b 100644 --- a/src/main/java/com/docutools/jocument/impl/ScalarPlaceholderData.java +++ b/src/main/java/com/docutools/jocument/impl/ScalarPlaceholderData.java @@ -13,7 +13,7 @@ public class ScalarPlaceholderData implements PlaceholderData { private final Function stringifier; public ScalarPlaceholderData(T value) { - this(value, Objects::toString); + this(value, v -> Objects.toString(v, "")); } public ScalarPlaceholderData(T value, Function stringifier) { diff --git a/src/main/java/com/docutools/jocument/impl/word/WordImageUtils.java b/src/main/java/com/docutools/jocument/impl/word/WordImageUtils.java index 9fe84f4b..43e46cb1 100644 --- a/src/main/java/com/docutools/jocument/impl/word/WordImageUtils.java +++ b/src/main/java/com/docutools/jocument/impl/word/WordImageUtils.java @@ -60,6 +60,7 @@ public static XWPFPicture insertImage(XWPFParagraph paragraph, Path path, ImageS var contentType = probeImageType(path); try (var in = Files.newInputStream(path, StandardOpenOption.READ)) { + logger.debug("Adding picture from path {} with content type {} and dimensions {} {}", path, contentType, dim.width, dim.height); return paragraph.createRun() .addPicture(in, contentType, path.getFileName().toString(), dim.width, dim.height); } catch (InvalidFormatException | IOException e) { diff --git a/src/test/java/com/docutools/jocument/ReflectionResolvingTests.java b/src/test/java/com/docutools/jocument/ReflectionResolvingTests.java index ce64e9ca..0a9ca86f 100644 --- a/src/test/java/com/docutools/jocument/ReflectionResolvingTests.java +++ b/src/test/java/com/docutools/jocument/ReflectionResolvingTests.java @@ -284,4 +284,15 @@ void shouldResolveUUIDtoString() { assertThat(id.get().toString(), equalTo(picardPerson.getId().toString())); } + + @Test + void shouldResolveNullToEmptyString() { + Person picardPerson = SampleModelData.PICARD_NULL; + var resolver = new ReflectionResolver(picardPerson); + + var name = resolver.resolve("firstName"); + + assertThat(name.get().toString(), equalTo("")); + } + } diff --git a/src/test/java/com/docutools/jocument/sample/model/SampleModelData.java b/src/test/java/com/docutools/jocument/sample/model/SampleModelData.java index f03ed689..b14f1bbe 100644 --- a/src/test/java/com/docutools/jocument/sample/model/SampleModelData.java +++ b/src/test/java/com/docutools/jocument/sample/model/SampleModelData.java @@ -13,6 +13,7 @@ public class SampleModelData { public static final Captain PICARD; public static final FutureCaptain FUTURE_PICARD; public static final Person PICARD_PERSON = new Person("Jean-Luc", "Picard", LocalDate.of(1948, 9, 23)); + public static final Person PICARD_NULL = new Person(null, "Picard", LocalDate.of(1948, 9, 23)); public static final List CAPTAINS; public static final Ship ENTERPRISE; public static final Ship ENTERPRISE_WITHOUT_SERVICES;