elasticsearch-java
elasticsearch-java copied to clipboard
Add serializeToString() method
This method serializeToString()
helps to generate the json String representation of any response or request object.
This could be useful for debugging or for other usages like consuming the search response objects within a JavaScript based frontend.
@swallez I think we should try to think something even more useful. Let me know if it's doable.
I'd love to have the method serializeToString()
available for every request or response object out of the box.
Instead of writing:
SearchResponse<Person> resp = ...;
String json = new JacksonJsonpMapper().serializeToString(resp);
We could write:
SearchResponse<Person> resp = ...;
String json = resp.toJson();
Would it be good for you?
Would it be good for you?
I'd like to limit the number of framework-related methods on API classes to the bare minimum, and I don't expect serializeToString
to be widely used. So better keep it on the mapper object (similar to what exists on Jackson's ObjectMapper
).
I don't really agree with the quote of @swallez '...and I don't expect serializeToString to be widely used....' The 'serializeToString' method is very useful for people not using Jackson but Gson for example. Even more useful would be to make the Json library used pluggable. Thanks for taking this into consideration!
@dadoonet When can we expect this to get merged?
@swallez I think that we can now use:
JsonpUtils.toJsonString(response, jacksonJsonpMapper);
So should we close this one?