springfox-data-rest: Inconsistent model returned between findAll and search methods
When using the latest snapshot (2.8.1-SNAPSHOT) of springfox-data-rest, I found an inconsistent behavior between findAll and search methods. Both methods return List<Entity> and produce the same JSON HAL similar to this:
{
"_embedded" : {
"someResourceRel" : [ {entities}]
},
"_links" : {...
but springfox reports different models used.
For findAll method a Resources<<Entity>> is reported while for search method a Resources<<List<<Entity>>>> is reported.
In the contract for declaration-spring-data-rest.json it is also defined a similar example with ResourcesOfPerson and ResourcesOfListOfPerson while it should probably produce the same result.
Resources is already a collection wrapper... I doubt it wraps a collection of additional collections.
I would gladly contribute a PR if this proves to be a bug indeed. Any thoughts?
Seems like a duplicate of #1980
Not quite... #1879, #1927 and #1980 report the different output format, i.e. the serialization of Resources which can almost be corrected using the Spring HATEOS object mapper (_halObjectMapper bean with Jackson2HalModule) but that is a different subject.
What this bug report is trying to address is the wrong content type inside the Resources instance.
The EntityFindAllExtractor @ line 71 resolves the return type using the RepositoryMetadata.getReturnedDomainClass method which extracts the domain type from the given collection.
resolver.resolve(Resources.class, repository.getReturnedDomainClass(handler.getMethod())));
On the other hand, EntitySearchExtractor @ line 82 resolves the return type directly from the method signature, thus presenting the return type as Resources<Collection<Entity>> instead of just Resources<Entity>
ResolvedType returnType = methodResolver.methodReturnType(handler);
if (Collections.isContainerType(returnType)) {
return resolver.resolve(Resources.class, returnType);
}
@iles-2e you are right thats a good catch, it should be
ResolvedType returnType = methodResolver.methodReturnType(handler);
if (Collections.isContainerType(returnType)) {
return resolver.resolve(Resources.class, Collections.collectionElementType(returnType));
}
Yeah PR's are most welcome!