This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git
The following commit(s) were added to refs/heads/master by this push: new a4e708e JOHNZON-361 Johnzon maven plugin generates invalid record classes (#80) a4e708e is described below commit a4e708e0c175977d850d79ce15c7d4999188911a Author: Raymond Augé <rotty3...@apache.org> AuthorDate: Sun Feb 20 12:29:55 2022 -0500 JOHNZON-361 Johnzon maven plugin generates invalid record classes (#80) Signed-off-by: Raymond Augé <rotty3...@apache.org> --- .../johnzon/maven/plugin/ExampleToModelMojo.java | 19 +++++++++++++++---- .../src/test/resources/SomeValue.record.java | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/johnzon-maven-plugin/src/main/java/org/apache/johnzon/maven/plugin/ExampleToModelMojo.java b/johnzon-maven-plugin/src/main/java/org/apache/johnzon/maven/plugin/ExampleToModelMojo.java index 2ce7ee7..af34fbd 100644 --- a/johnzon-maven-plugin/src/main/java/org/apache/johnzon/maven/plugin/ExampleToModelMojo.java +++ b/johnzon-maven-plugin/src/main/java/org/apache/johnzon/maven/plugin/ExampleToModelMojo.java @@ -129,10 +129,10 @@ public class ExampleToModelMojo extends AbstractMojo { } if (useRecord) { - writer.write("public record " + javaName + "(\n"); + writer.write("public record " + javaName + "("); writer.write(memBuffer.toString()); } else { - writer.write("public class " + javaName + " {\n"); + writer.write("public class " + javaName + " {"); writer.write(memBuffer.toString()); } writer.write("}\n"); @@ -146,6 +146,9 @@ public class ExampleToModelMojo extends AbstractMojo { final Map<String, JsonObject> nestedTypes = new TreeMap<>(); { final Iterator<Map.Entry<String, JsonValue>> iterator = object.entrySet().iterator(); + if (!object.isEmpty()) { + writer.write("\n"); + } while (iterator.hasNext()) { final Map.Entry<String, JsonValue> entry = iterator.next(); final String key = entry.getKey(); @@ -190,6 +193,14 @@ public class ExampleToModelMojo extends AbstractMojo { } } + if (object.isEmpty()) { + if (useRecord) { + writer.write(") {\n"); + } else { + writer.write("\n"); + } + } + if (!object.isEmpty() && !nestedTypes.isEmpty()) { writer.write("\n"); } @@ -198,9 +209,9 @@ public class ExampleToModelMojo extends AbstractMojo { while (entries.hasNext()) { final Map.Entry<String, JsonObject> entry = entries.next(); if (useRecord) { - writer.write(prefix + "public static record " + entry.getKey() + "(\n"); + writer.write(prefix + "public static record " + entry.getKey() + "("); } else { - writer.write(prefix + "public static class " + entry.getKey() + " {\n"); + writer.write(prefix + "public static class " + entry.getKey() + " {"); } generateFieldsAndMethods(writer, entry.getValue(), " " + prefix, imports); writer.write(prefix + "}\n"); diff --git a/johnzon-maven-plugin/src/test/resources/SomeValue.record.java b/johnzon-maven-plugin/src/test/resources/SomeValue.record.java index 120d2bd..7d59a64 100644 --- a/johnzon-maven-plugin/src/test/resources/SomeValue.record.java +++ b/johnzon-maven-plugin/src/test/resources/SomeValue.record.java @@ -55,6 +55,6 @@ public record SomeValue( } } - public static record SecondaryMetrics( + public static record SecondaryMetrics() { } }