Issue 5413 - Use ConstructorBased Injection for ObjectMapper (#5430)

* Converting to constructor based injection

* Correcting spelling mistake

* Adding the bean for ObjectMapper

* Adding files modified by running the petstore scripts

* Adding final qualifier to objectMapper variable in apiController mustache
This commit is contained in:
Elizabeth Thomas
2017-04-25 10:11:18 -05:00
committed by wing328
parent 745951c1ce
commit efb337dd92
9 changed files with 72 additions and 40 deletions

View File

@@ -32,6 +32,12 @@ import javax.validation.Valid;
@Controller
{{#operations}}
public class {{classname}}Controller implements {{classname}} {
private final ObjectMapper objectMapper;
public {{classname}}Controller(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}
{{#isDelegate}}
private final {{classname}}Delegate delegate;
@@ -49,11 +55,7 @@ public class {{classname}}Controller implements {{classname}} {
{{^isDelegate}}
{{^async}}
{{#examples}}
{{#-first}}
ObjectMapper objectMapper = new ObjectMapper();
{{/-first}}
if (accept != null && accept.contains("{{{contentType}}}")) {
return new ResponseEntity<{{>returnTypes}}>(objectMapper.readValue("{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{example}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{>exampleReturnTypes}}.class), HttpStatus.OK);
}