Skip to content

Conversation

mdeinum
Copy link
Contributor

@mdeinum mdeinum commented Dec 14, 2020

Currently when reading/writing JSON and using the reader/marshaller provided
and you want a custom Gson or ObjectMapper instance it still creates the not
needed instance. Move the construction to a constructor and provide a constructor
to directly pass in the pre-configured Gson or ObjectMapper instance.

The same approach is used in Spring itself where Gson or ObjectMapper instances
can be passed in.

Currently when reading/writing JSON and using the reader/marshaller provided
and you want a custom Gson or ObjectMapper instance it still creates the not
needed instance. Move the construction to a constructor and provide a constructor
to directly pass in the pre-configured Gson or ObjectMapper instance.

The same approach is used in Spring itself where Gson or ObjectMapper instances
can be passed in.
*/
public class GsonJsonObjectMarshaller<T> implements JsonObjectMarshaller<T> {

private Gson gson = new Gson();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the improvement suggested in this PR, there shouldn't be an inline instantiation of Gson here (similar to what has been done in other classes in this change set). I will update that on merge.

@fmbenhassine
Copy link
Contributor

Rebased and merged as af14a2e. Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: backport-to-4.2.x Issues that will be back-ported to the 4.2.x line in: infrastructure pr-for: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants