Skip to content

Wrong marshalling from ControllerAdvice #279

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

Open
fdw opened this issue Jan 16, 2015 · 6 comments
Open

Wrong marshalling from ControllerAdvice #279

fdw opened this issue Jan 16, 2015 · 6 comments

Comments

@fdw
Copy link

fdw commented Jan 16, 2015

I'm using an exception handler annotated with @ControllerAdvice in a Spring-MVC application. For some errors, I want to return a useful response containing HAL-links.

Unfortunately, those links are not rendered correctly in JSON as "_links", but rather as "links". It seems that when using @ControllerAdvice, the SerializerMixins are not configured for Jackson: Through debugging, I noticed that DefaultSerializerProvider._config.mixInAnnotations is empty here, but contains, among others, "org.springframework.hateoas.hal.ResourceSupportMixin" when marshalling from an ordinary @RestController. The content-type is correctly set to "application/hal+json".

Did I miss something? Is there a way to render correct links?

@fdw
Copy link
Author

fdw commented Jan 27, 2015

Any news on this?

@schvanhugten
Copy link

You could use the following work-around?

@odrotbohm
Copy link
Member

What do you actually return from your controller advice methods?

@fdw
Copy link
Author

fdw commented Feb 27, 2015

I return a custom object (let's call it ErrorResource) that inherits from ResourceSupport, just like I do in other controllers. If I return such an ErrorResource from a regular controller, the links are rendered correctly, so this seems to work.

@hantsy
Copy link

hantsy commented Nov 27, 2015

I encountered the same problem here when I added @JsonSerialize(using = Jackson2HalModule.HalResourcesSerializer .class) and got exception Class org.springframework.hateoas.hal.Jackson2HalModule$HalResourcesSerializer has no default (no arg) constructor. I will try other solutions for this.

I posted my question here.

http://stackoverflow.com/questions/33957999/custom-error-is-not-rendered-as-hal-in-spring-boot-1-3-and-spring-hateoas-0-19

@fdw
Copy link
Author

fdw commented Aug 9, 2016

Hi, it seems that nothing has changed since the original report. Are there any plans for a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants