Skip to content

Commit

Permalink
chore: Reuse same JSON mapping instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
nstdio committed Mar 27, 2022
1 parent f049ef0 commit ec0ca6d
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ static boolean hasAnyImplementation() {
@Override
public JsonMapping get() {
if (isJacksonPresent()) {
return new JacksonJsonMapping();
return JacksonMappingHolder.INSTANCE;
}
if (isGsonPresent()) {
return new GsonJsonMapping();
return GsonMappingHolder.INSTANCE;
}

throw new JsonMappingProviderNotFoundException(NO_JSON_MAPPING_FOUND);
}

private static class JacksonMappingHolder {
private static final JacksonJsonMapping INSTANCE = new JacksonJsonMapping();
}

private static class GsonMappingHolder {
private static final GsonJsonMapping INSTANCE = new GsonJsonMapping();
}
}

0 comments on commit ec0ca6d

Please sign in to comment.