Sometimes we need extract data from child node instead of root document. For example get index mappings from ElasticSearch:

@HttpExchange("http://localhost:9200")
public interface ElasticSearchIndexOperations {

    @GetExchange("/{index}/_mapping")
    @JsonPointer("/${index}/mappings")
    Mappings getMapping(@PathVariable String index);

 }

NOTE: placeholders in @JsonPointer("/${index}/mappings") need to be resolved base on method parameters.

Comment From: rstoyanchev

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.

Comment From: quaff

It seems JSONPath is more popular, It would be nice both are supported.

Comment From: sdeleuze

A few open questions and remarks after discussing with @simonbasle: - This potential feature has conceptually some connections with our @JsonView support (taking a subset versus filtering without changing the structure, both to reduce the amount of data serialized) - 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). - If we support this for @HttpExchange, we should probably support it for @RequestMapping, shouldn't we? - On functional API side, I think RestClient does not provide a way to pass hints unlike WebClient, could you please confirm @poutsma? - IMO JSONPath is too complex and not supported by Jackson for that use case, so not something we should support.

Comment From: poutsma

  • On functional API side, I think RestClient does not provide a way to pass hints unlike WebClient, could you please confirm @poutsma?

Indeed, because RestClient is based on the existing HttpMessageConverters, which do not support hints.

Comment From: sdeleuze

Ah good point, we use MappingJacksonValue to pass JSON views, so JSON filters support could probably be added the same way.

Comment From: rstoyanchev

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.

Comment From: sdeleuze

Feedback after a related discussion during our team meeting: - For purely client side use cases, we could indeed support JsonPointer arguments as the related instance would be provided by the user code. - I remain a bit puzzled by the fact we have not identified yet a proper way to expose such feature on server-side due to the lack of @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.