Use of RestTemplate
rjain-pivotal opened this issue · 1 comments
rjain-pivotal commented
Do you seen any (performance) benefits of using RestTemplate to create the Object from JSON vs the way you are creating from request parameters.
Here are the two comparisons, not sure which will perform better and which is a better choice.
Compare the code below to your GreeingApplication.java
@Autowired
private RestTemplate rest;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String hello() {
Greeting greeting = rest.getForObject("http://greeting-service/greeting", Greeting.class);
return greeting.getMessage();
}
private static class Greeting {
private String message;
@JsonCreator
public Greeting(@JsonProperty("message") String message) {
this.message = message;
}
public String getMessage() {
return this.message;
}
}
royclarkson commented
Thanks for the feedback. This issue has been open for a while, so I'm not sure what version of the code you were referring to. Please review the latest in master and let us know if you have other concerns. Regarding building a RestTemplate request via parameters, or marshaling via objects, either way is a valid approach.