Is there any significant performance difference between the following two?
String json = mapper.writeValueAsString(searchResult);
response.getWriter().write(json);
vs
mapper.writeValue(response.getWriter(), searchResult);
Is there any significant performance difference between the following two?
String json = mapper.writeValueAsString(searchResult);
response.getWriter().write(json);
vs
mapper.writeValue(response.getWriter(), searchResult);
writeValueAsString
JavaDoc says:
Method that can be used to serialize any Java value as a String. Functionally equivalent to calling writeValue(Writer,Object) with StringWriter and constructing String, but more efficient.
So, in case, you want to write JSON
to String
is much better to use this method than writeValue
. Both these methods use _configAndWriteValue
.
In your case it is better to write JSON
directly to response.getWriter()
than generating String
object and after that writing it to response.getWriter()
.