Skip to content

In a @JsonPath projection a List<interface> property always returns a list with only one element #2270

Closed
@jekutzsche

Description

@jekutzsche

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);
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions