Provide constructors for injection
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.
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
1b936a2809
commit
b3d5d31bfd
@@ -34,9 +34,7 @@ public class GsonJsonFileItemWriterFunctionalTests extends JsonFileItemWriterFun
|
||||
@Override
|
||||
protected JsonObjectMarshaller<Trade> getJsonObjectMarshallerWithPrettyPrint() {
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
GsonJsonObjectMarshaller<Trade> jsonObjectMarshaller = new GsonJsonObjectMarshaller<>();
|
||||
jsonObjectMarshaller.setGson(gson);
|
||||
return jsonObjectMarshaller;
|
||||
return new GsonJsonObjectMarshaller<>(gson);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,9 +35,7 @@ public class JacksonJsonFileItemWriterFunctionalTests extends JsonFileItemWriter
|
||||
protected JsonObjectMarshaller<Trade> getJsonObjectMarshallerWithPrettyPrint() {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
|
||||
JacksonJsonObjectMarshaller<Trade> jsonObjectMarshaller = new JacksonJsonObjectMarshaller<>();
|
||||
jsonObjectMarshaller.setObjectMapper(objectMapper);
|
||||
return jsonObjectMarshaller;
|
||||
return new JacksonJsonObjectMarshaller<>(objectMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user