Skip to content

Commit

Permalink
java-server: Generate ApiJaxbJsonProvider as an abstract class so use…
Browse files Browse the repository at this point in the history
…rs can modify the implementation without it being overwritten
  • Loading branch information
karlvr committed Sep 7, 2024
1 parent 0cddbff commit 1906f7d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-worms-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@openapi-generator-plus/java-jaxrs-server-generator": minor
---

Generate ApiJaxbJsonProvider as an abstract class so users can modify the implementation without it being overwritten
4 changes: 3 additions & 1 deletion packages/java-jaxrs-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ export const createGenerator: CodegenGeneratorConstructor<JavaGeneratorContext>

const providerPackagePath = generatorOptions.apiProviderPackage ? packageToPath(generatorOptions.apiProviderPackage) : undefined
if (providerPackagePath) {
await emit('ApiJaxbJsonProvider', path.join(outputPath, relativeApiImplSourceOutputPath, providerPackagePath, 'ApiJaxbJsonProvider.java'),
await emit('AbstractApiJaxbJsonProvider', path.join(outputPath, relativeApiImplSourceOutputPath, providerPackagePath, 'AbstractApiJaxbJsonProvider.java'),
{ ...rootContext }, true, hbs)
await emit('ApiJaxbJsonProvider', path.join(outputPath, relativeApiImplSourceOutputPath, providerPackagePath, 'ApiJaxbJsonProvider.java'),
{ ...rootContext }, false, hbs)
}

if (context.additionalExportTemplates) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package {{apiProviderPackage}};

{{>generatedAnnotation}}
public abstract class AbstractApiJaxbJsonProvider extends com.fasterxml.jackson.{{#if @root.useJakarta}}jakarta.rs{{else}}jaxrs{{/if}}.json.{{#if @root.useJakarta}}JacksonXmlBindJsonProvider{{else}}JacksonJaxbJsonProvider{{/if}} {

public AbstractApiJaxbJsonProvider() {
super();

this.setMapper(createMapper());
}

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

}
7 changes: 1 addition & 6 deletions packages/java-jaxrs-server/templates/ApiJaxbJsonProvider.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ package {{apiProviderPackage}};
@{{javax}}.ws.rs.Consumes({"application/json; charset=UTF-8", "application/*+json; charset=UTF-8" })
@{{javax}}.ws.rs.ext.Provider
{{>hooks/jaxbJsonProviderAnnotations}}
{{>generatedAnnotation}}
public class ApiJaxbJsonProvider extends com.fasterxml.jackson.{{#if @root.useJakarta}}jakarta.rs{{else}}jaxrs{{/if}}.json.{{#if @root.useJakarta}}JacksonXmlBindJsonProvider{{else}}JacksonJaxbJsonProvider{{/if}} {
public class ApiJaxbJsonProvider extends {{apiProviderPackage}}.AbstractApiJaxbJsonProvider {

public ApiJaxbJsonProvider() {
super();

{{>frag/jaxbJsonProviderBody}}

this.setMapper(mapper);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ mapper.registerModule(new com.fasterxml.jackson.datatype.jdk8.Jdk8Module());
/* Support Java time object types */
mapper.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
mapper.configure(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);

return mapper;

0 comments on commit 1906f7d

Please sign in to comment.