Skip to content

Generics bounds too strict in RepresentationModelAssemblerSupport #1122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Bert-R opened this issue Nov 11, 2019 · 13 comments
Closed

Generics bounds too strict in RepresentationModelAssemblerSupport #1122

Bert-R opened this issue Nov 11, 2019 · 13 comments
Assignees
Labels
in: core Core parts of the project type: bug
Milestone

Comments

@Bert-R
Copy link

Bert-R commented Nov 11, 2019

With Spring Hateoas 0.25, we had code like this:

public class StatisticsResource extends Resource<StatisticsDto>
{
    :
}

public class StatisticsResourceAssembler
        extends ResourceAssemblerSupport<StatisticsDto, StatisticsResource>
{
    :
}

Now I'm migrating it to 1.0, like this:

public class StatisticsResource extends EntityModel<StatisticsDto>
{
    :
}

public class StatisticsResourceAssembler
        extends RepresentationModelAssemblerSupport<StatisticsDto, StatisticsResource>
{
    :
}

This however doesn't compile:

extends RepresentationModelAssemblerSupport<StatisticsDto, StatisticsResource>
                                                           ^
where D is a type-variable:
    D extends RepresentationModel<D> declared in class RepresentationModelAssemblerSupport

Any idea what's going wrong here?

P.S. I asked this on StackOverflow first and got the suggestion to use SimpleRepresentationModelAssembler, but that only works for this simple case. We have more complex cases too.

@odrotbohm
Copy link
Member

This is glitch in our generics declarations. Will be fixed ASAP.

@odrotbohm odrotbohm self-assigned this Nov 22, 2019
@odrotbohm odrotbohm added this to the 1.1.0.M1 milestone Nov 22, 2019
@odrotbohm odrotbohm changed the title Entity model inheritance Spring Hateoas 1.0 Generics bounds to strict in RepresentationModelAssemblerSupport Nov 22, 2019
@odrotbohm odrotbohm added in: core Core parts of the project type: bug labels Nov 22, 2019
odrotbohm added a commit that referenced this issue Nov 22, 2019
…port.

We constrained the RepresentationModel type parameter in a way that non of the RepresentationModel subclasses we provide aren't usable with it. That's now fixed by loosing that restriction to an arbitrary type.
odrotbohm added a commit that referenced this issue Nov 22, 2019
@odrotbohm odrotbohm changed the title Generics bounds to strict in RepresentationModelAssemblerSupport Generics bounds too strict in RepresentationModelAssemblerSupport Nov 22, 2019
@Bert-R
Copy link
Author

Bert-R commented Nov 22, 2019

Thanks a lot for the quick fix!

@Bert-R
Copy link
Author

Bert-R commented Nov 29, 2019

I have tested with the snapshot build and this is fixed. Thanks!

@margfernan
Copy link

Please, I'm having the same issue with spring boot 2.2.2 and spring Hateoas v1. What is the version of Spring Hateoas with this issue solved?

@gregturn
Copy link
Contributor

gregturn commented Dec 17, 2019

@margfernan If you use Spring Boot 2.3.0.BUILD-SNAPSHOT with <spring-hateoas.version> configured for 1.1.0.BUILD-SNAPSHOT, you can take it out for a spin.

I'm a little vague on whether or not 1.1.0.BUILD-SNAPSHOT works with current release of Boot 2.2.2.RELEASE or not.

@margfernan
Copy link

margfernan commented Dec 18, 2019

@odrotbohm and @gregturn thank you for your response but I tried with the version 1.1.0.BUILD-SNAPSHOT but the error still appears.
1)When is released the new version of the spring hateoas with this fix? or,
2)What version of the Spring Boot ( version > 2.x.x) recommend you to me to use Hateoas?
Last it, I attached a screenshot with the error.

Hateoas-assembler-issue

Even, if I extend the assembler class to RepresentationModelAssemblerSupport, it happen the same issue.
Dependencies:
Spring Boot --> 2.2.2.RELEASE
groupId: org.springframework.boot -> artefactId : spring-boot-starter-hateoas (tried to 1.0.2.RELEASE and 1.1.0.BUILD-SNAPSHOT versions.)

Please, I need a urgent solution.
Best Regards
Martin

@odrotbohm
Copy link
Member

As indicated by the error message you need to properly type ClientResourceDto to extends RepresentationModel<ClientResourceDto>.

The 1.1.0.BUILD-SNAPSHOTs should actually work with current Boot 2.2 as well. We could issue a first milestone of the former pretty soon if that helps. I'm afraid a GA release of Spring HATEOAS 1.1 is still a bit far out.

@Bert-R
Copy link
Author

Bert-R commented Dec 18, 2019

When I'm not mistaken, this is a compile-time fix that has no side-effects. Is it possible to backport this to 1.0.x and release it earlier?

@odrotbohm
Copy link
Member

It changes API, which is why I was hesitant to back port it. On the other hand, IIUC it's completely unusable in the 1.0.x branch anyway, which means that there's nothing in there we can break even more than it already is broken, right?

@Bert-R
Copy link
Author

Bert-R commented Dec 18, 2019

Indeed, that's how I see it.

@odrotbohm
Copy link
Member

Looks like we've already done this with #1126.

@Bert-R
Copy link
Author

Bert-R commented Dec 18, 2019

#1126 was included in 1.0.2. I've tested this on 1.0.2 and can confirm it is fixed.
@odrotbohm Thanks!

@margfernan
Copy link

As indicated by the error message you need to properly type ClientResourceDto to extends RepresentationModel<ClientResourceDto>.

The 1.1.0.BUILD-SNAPSHOTs should actually work with current Boot 2.2 as well. We could issue a first milestone of the former pretty soon if that helps. I'm afraid a GA release of Spring HATEOAS 1.1 is still a bit far out.

It works! Thanks a lot!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Core parts of the project type: bug
Projects
None yet
Development

No branches or pull requests

4 participants