Skip to content

Commit

Permalink
java-server: Make AbstractApiJaxbJsonProvider more customisable in code
Browse files Browse the repository at this point in the history
  • Loading branch information
karlvr committed Sep 9, 2024
1 parent 12fd4b0 commit 6eefd96
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .changeset/pink-starfishes-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@openapi-generator-plus/java-jaxrs-server-generator": minor
---

Make AbstractApiJaxbJsonProvider more customisable in code.

Rather than relying on replacing a Handlebars frag.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,37 @@ public abstract class AbstractApiJaxbJsonProvider extends com.fasterxml.jackson.
}

protected com.fasterxml.jackson.databind.ObjectMapper createMapper() {
{{>frag/jaxbJsonProviderBody}}
com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();

/* We don't serialise null values so the client can treat them as null or undefined as they see fit */
mapper.setSerializationInclusion(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL);

/* Support PATCH requests using java.util.Optional */
if (isRegisterJdk8Module()) {
mapper.registerModule(createJdk8Module());
}

/* Support Java time object types */
mapper.registerModule(createJavaTimeModule());
mapper.configure(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, isWriteDatesAsTimestamps());

return mapper;
}

protected boolean isRegisterJdk8Module() {
return true;
}

protected com.fasterxml.jackson.datatype.jdk8.Jdk8Module createJdk8Module() {
return new com.fasterxml.jackson.datatype.jdk8.Jdk8Module();
}

protected com.fasterxml.jackson.datatype.jsr310.JavaTimeModule createJavaTimeModule() {
return new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule();
}

protected boolean isWriteDatesAsTimestamps() {
return false;
}

}
13 changes: 0 additions & 13 deletions packages/java-jaxrs-server/templates/frag/jaxbJsonProviderBody.hbs

This file was deleted.

0 comments on commit 6eefd96

Please sign in to comment.