From abaf71488c98b8e12ba4ed54ec9c500e8618aa65 Mon Sep 17 00:00:00 2001 From: An Phi Date: Fri, 14 Apr 2023 12:51:29 -0400 Subject: [PATCH] Address review comments --- .../server/BaseServerJacksonJsonProvider.java | 13 +++----- ...dSDLCServerForTestJacksonJsonProvider.java | 27 +++++++-------- .../server/gitlab/TestGitLabProjectId.java | 2 +- .../resources/SDLCServerClientRule.java | 33 ++++++++----------- 4 files changed, 30 insertions(+), 45 deletions(-) diff --git a/legend-sdlc-server-shared/src/main/java/org/finos/legend/sdlc/server/BaseServerJacksonJsonProvider.java b/legend-sdlc-server-shared/src/main/java/org/finos/legend/sdlc/server/BaseServerJacksonJsonProvider.java index 79f17a97cd..3ace2b7450 100644 --- a/legend-sdlc-server-shared/src/main/java/org/finos/legend/sdlc/server/BaseServerJacksonJsonProvider.java +++ b/legend-sdlc-server-shared/src/main/java/org/finos/legend/sdlc/server/BaseServerJacksonJsonProvider.java @@ -22,18 +22,13 @@ public class BaseServerJacksonJsonProvider extends JacksonJsonProvider implements ContextResolver { - private final ObjectMapper objectMapper; - - public BaseServerJacksonJsonProvider() - { - objectMapper = new ObjectMapper(); - objectMapper.findAndRegisterModules(); - objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); - } + private final ObjectMapper objectMapper = new ObjectMapper() + .findAndRegisterModules() + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); @Override public ObjectMapper getContext(Class type) { - return objectMapper; + return this.objectMapper; } } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/LegendSDLCServerForTestJacksonJsonProvider.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/LegendSDLCServerForTestJacksonJsonProvider.java index c99ce61910..d0f15680cc 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/LegendSDLCServerForTestJacksonJsonProvider.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/LegendSDLCServerForTestJacksonJsonProvider.java @@ -32,25 +32,20 @@ public class LegendSDLCServerForTestJacksonJsonProvider extends JacksonJsonProvider implements ContextResolver { - private final ObjectMapper objectMapper; - - public LegendSDLCServerForTestJacksonJsonProvider() - { - objectMapper = new ObjectMapper(); - objectMapper.findAndRegisterModules(); - objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - objectMapper.addMixIn(Project.class, InMemoryMixins.Project.class); - objectMapper.addMixIn(Workspace.class, InMemoryMixins.Workspace.class); - objectMapper.addMixIn(Entity.class, InMemoryMixins.Entity.class); - objectMapper.addMixIn(Revision.class, InMemoryMixins.Revision.class); - objectMapper.addMixIn(ProjectDependency.class, ProjectDependencyMixin.class); - objectMapper.addMixIn(VersionId.class, VersionIdMixin.class); - objectMapper.addMixIn(Review.class, InMemoryMixins.Review.class); - } + private final ObjectMapper objectMapper = new ObjectMapper() + .findAndRegisterModules() + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .addMixIn(Project.class, InMemoryMixins.Project.class) + .addMixIn(Workspace.class, InMemoryMixins.Workspace.class) + .addMixIn(Entity.class, InMemoryMixins.Entity.class) + .addMixIn(Revision.class, InMemoryMixins.Revision.class) + .addMixIn(ProjectDependency.class, ProjectDependencyMixin.class) + .addMixIn(VersionId.class, VersionIdMixin.class) + .addMixIn(Review.class, InMemoryMixins.Review.class); @Override public ObjectMapper getContext(Class type) { - return objectMapper; + return this.objectMapper; } } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/TestGitLabProjectId.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/TestGitLabProjectId.java index 3327cff031..85436859c2 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/TestGitLabProjectId.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/TestGitLabProjectId.java @@ -87,6 +87,6 @@ public void testParseProjectId() private long[] getGitLabIdsForTest() { - return new long[]{0, 1, 2, 3, 4, 5, 64, 127, 511, 1024, 17_560_438, 1_030_991_200, Integer.MAX_VALUE}; + return new long[]{0, 1, 2, 3, 4, 5, 64, 127, 511, 1024, 17_560_438, 1_030_991_200, Integer.MAX_VALUE, Long.MAX_VALUE}; } } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/resources/SDLCServerClientRule.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/resources/SDLCServerClientRule.java index 7a06fba03d..aecfcb8829 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/resources/SDLCServerClientRule.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/resources/SDLCServerClientRule.java @@ -73,29 +73,24 @@ private Client createClient() static class SDLCServerClientRuleJacksonJsonProvider extends JacksonJsonProvider implements ContextResolver { - private final ObjectMapper objectMapper; - - public SDLCServerClientRuleJacksonJsonProvider() - { - objectMapper = new ObjectMapper(); - this.objectMapper.findAndRegisterModules(); - this.objectMapper.enable(SerializationFeature.INDENT_OUTPUT); - this.objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - this.objectMapper.addMixIn(Project.class, InMemoryMixins.Project.class); - this.objectMapper.addMixIn(Workspace.class, InMemoryMixins.Workspace.class); - this.objectMapper.addMixIn(Entity.class, InMemoryMixins.Entity.class); - this.objectMapper.addMixIn(Revision.class, InMemoryMixins.Revision.class); - this.objectMapper.addMixIn(Review.class, InMemoryMixins.Review.class); - this.objectMapper.addMixIn(ProjectRevision.class, ProjectRevisionMixin.class); - this.objectMapper.addMixIn(ProjectDependency.class, ProjectDependencyMixin.class); - this.objectMapper.addMixIn(VersionId.class, VersionIdMixin.class); - } + private final ObjectMapper objectMapper = new ObjectMapper() + .findAndRegisterModules() + .enable(SerializationFeature.INDENT_OUTPUT) + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .addMixIn(Project.class, InMemoryMixins.Project.class) + .addMixIn(Workspace.class, InMemoryMixins.Workspace.class) + .addMixIn(Entity.class, InMemoryMixins.Entity.class) + .addMixIn(Revision.class, InMemoryMixins.Revision.class) + .addMixIn(Review.class, InMemoryMixins.Review.class) + .addMixIn(ProjectRevision.class, ProjectRevisionMixin.class) + .addMixIn(ProjectDependency.class, ProjectDependencyMixin.class) + .addMixIn(VersionId.class, VersionIdMixin.class); @Override public ObjectMapper getContext(Class type) { - return objectMapper; + return this.objectMapper; } } }