Skip to content

Commit 263a9f8

Browse files
authored
Merge pull request #1256 from ntgussoni/fix/marina-javatime-json-serialization
fix(marina): serialize Java 8 date/time in api.js Handlebars json helper
2 parents d306a25 + 65178bc commit 263a9f8

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

boat-scaffold/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
<version>4.3.1</version>
5454
</dependency>
5555

56+
<dependency>
57+
<groupId>com.fasterxml.jackson.datatype</groupId>
58+
<artifactId>jackson-datatype-jsr310</artifactId>
59+
</dependency>
60+
5661
<dependency>
5762
<groupId>com.backbase.oss</groupId>
5863
<artifactId>boat-engine</artifactId>

boat-scaffold/src/main/java/com/backbase/oss/codegen/marina/BoatHandlebarsEngineAdapter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonInclude;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.fasterxml.jackson.databind.SerializationFeature;
6+
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
67
import com.github.jknack.handlebars.Context;
78
import com.github.jknack.handlebars.Handlebars;
89
import com.github.jknack.handlebars.Helper;
@@ -78,6 +79,8 @@ boolean isValidField(
7879
return "";
7980
});
8081
ObjectMapper objectMapper = new ObjectMapper();
82+
objectMapper.registerModule(new JavaTimeModule());
83+
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
8184
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
8285
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
8386
Helper<Object> instance = new Jackson2Helper(objectMapper);

boat-scaffold/src/test/java/com/backbase/oss/codegen/marina/BoatMarinaTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ void testGenerate() throws IOException {
3030
}
3131
}
3232

33+
@Test
34+
void testGenerateDocsWithDateTimeExamples() throws IOException {
35+
generateDocs(getFile("/openapi-with-examples/openapi-with-multiple-permissions.yaml"));
36+
37+
File index = new File("target/marina-docs/api.js");
38+
String generated = String.join(" ", Files.readAllLines(Paths.get(index.getPath())));
39+
assertTrue(generated.contains("2017-10-04T14:54:36Z"));
40+
}
41+
3342
@Test
3443
void testGenerateDocs() throws IOException {
3544
generateDocs(getFile("/openapi-with-examples/openapi-with-json.yaml"));

0 commit comments

Comments
 (0)