Open quaff opened 2 years ago
This is something we could do, but will need to isolate use of APIs specific to JSON libraries.
Jackson supports setting JsonPointer on ObjectReader
, so we could start with that in AbstractJackson2Decoder
if it's passed as a hint. The next question is how to pass the hint in. We could use HttpRequestValues
to pass it to WebClientAdapter
, but no good way from there to pass a hint. The closest is calling ClientResponse#body(BodyExtractor)
with a decorated BodyExtractor
, but we could also add a more first-class option. Perhaps an overloaded method on ClientResponse
similar to ServerRequest.
It seems JSONPath is more popular, It would be nice both are supported.
A few open questions and remarks after discussing with @simonbasle:
@JsonView
support (taking a subset versus filtering without changing the structure, both to reduce the amount of data serialized)@JsonPointer
annotation and I am not sure Spring should introduce that as too Jackson/JSON specific (@JsonView
is a Jackson annotation that we reuse, but I am not sure a @JsonPointer
annotation makes sense on Jackson side).@HttpExchange
, we should probably support it for @RequestMapping
, shouldn't we?RestClient
does not provide a way to pass hints unlike WebClient
, could you please confirm @poutsma?
- On functional API side, I think
RestClient
does not provide a way to pass hints unlikeWebClient
, could you please confirm @poutsma?
Indeed, because RestClient
is based on the existing HttpMessageConverters, which do not support hints.
Ah good point, we use MappingJacksonValue
to pass JSON views, so JSON filters support could probably be added the same way.
Jackson does not provide a
@JsonPointer
annotation and I am not sure Spring should introduce that as too Jackson/JSON specific (@JsonView
is a Jackson annotation that we reuse, but I am not sure a@JsonPointer
annotation makes sense on Jackson side).
Jackson has a JsonPointer
type and we could take that into account if it is passed in as an argument. It should be clear it applies to the response since you shouldn't need that for the request body.
Feedback after a related discussion during our team meeting:
JsonPointer
arguments as the related instance would be provided by the user code.@JsonPointer
annotation, as I believe it would be equally useful for that use case, and doing that just for declarative HTTP client looks a bit niche.
Sometimes we need extract data from child node instead of root document. For example get index mappings from ElasticSearch:
NOTE: placeholders in
@JsonPointer("/${index}/mappings")
need to be resolved base on method parameters.