Closed
Description
The @JsonPath
projection of a List of an interface type returns only the first element even if the list should contain more elements.
The following code hopefully makes the circumstances clear.
var payload = template.exchange("https://…", HttpMethod.GET, new HttpEntity<Void>(headers), UserPayload.class).getBody();
var users = payload.users();
users.size() == 1 is also true if the list had to contain more elements
@ProjectedPayload
interface UserPayload {
@JsonPath("$..person")
List<Users> users();
interface Users {
public String getFirstName();
public String getLastName();
}
}
Responsible for the error is the following code in InputMessageProjecting.invoke
:
if (returnType.getRequiredActualType().getType().isInterface()) {
List<?> result = context.read(jsonPath);
return result.isEmpty() ? null : result.get(0);
}