Skip to content

Hateos HandlerInstantiator overrides Jackson's HandlerInstantiator #3979

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
countrogue opened this issue Sep 18, 2015 · 7 comments
Closed

Hateos HandlerInstantiator overrides Jackson's HandlerInstantiator #3979

countrogue opened this issue Sep 18, 2015 · 7 comments
Assignees
Labels
status: invalid An issue that we don't feel is valid

Comments

@countrogue
Copy link

Im trying to autowire my JsonSerializer/JsonDeserializer.

    return new Jackson2ObjectMapperBuilder()
                          .deserializerByType(ObjectX.class, objectXDeserializerBean)
                          .applicationContext(applicationContext);

It works with the global deserializer objectXDeserializerBean(above), but when deserializing specific fields like the following(below) it doesn't work:

class ObjectY {
    @JsonDeserialize(using = ObjectZDeserializer.class)
    private ObjectZ myField;
}

The problem is that HypermediaAutoConfiguration is overriding the HandlerInstantiator in jackson2ObjectMapper so the only work around i can do right now is to set spring.hateoas.apply-to-primary-object-mapper=false. WIth that i was forced to abandon hateos in my responses. Can anyone help me with this?

@philwebb
Copy link
Member

@countrogue What version of Spring Boot are you using? @wilkinsona Does this sound like a duplicate of one of the existing Jackson issues you've already dealt with?

@philwebb philwebb added the status: waiting-for-feedback We need additional information before we can continue label Sep 21, 2015
@countrogue
Copy link
Author

@philwebb im using spring-boot v1.2.5.RELEASE

@wilkinsona
Copy link
Member

@philwebb I haven't already dealt with it, but it might turn out to be a duplicate of #3891. However, at the moment at least, I'm only planning to tackle #3891 in 1.3 as I think it might require some changes that are larger when we'd want to ship in 1.2.x.

@wilkinsona wilkinsona removed the status: waiting-for-feedback We need additional information before we can continue label Sep 24, 2015
@wilkinsona wilkinsona self-assigned this Sep 24, 2015
@wilkinsona wilkinsona added the type: bug A general bug label Sep 24, 2015
@wilkinsona
Copy link
Member

@countrogue I'm struggling to reproduce this. Can you please put together a small sample that reproduces the problem?

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed type: bug A general bug labels Sep 24, 2015
@countrogue
Copy link
Author

@wilkinsona Hi you can download the sample project from here.

@wilkinsona
Copy link
Member

Thanks for the sample. It didn't appear to reproduce the problem, but it was sufficient for the penny to drop about what you're trying to do.

Unfortunately, Jackson only allows an ObjectMapper to be configured with a single HandlerInstantiator which means that Spring HATEOAS's HalHandlerInstantiator and Spring Framework's SpringHandlerInstantiator cannot be easily used together. In other words, out of the box, you have to choose between having HAL formatted responses or being about to use dependency injection in your serializers, deserializers, etc.

You could create and use your own HandlerInstantiator that delegates to HalHandlerInstantiator and, if it returns null, delegate to SpringHandlerInstantiator instead. Unfortunately, @olivergierke considers HalHandlerInstantiator to be private API in Spring HATEOAS so I wouldn't recommend depending on it directly.

In summary, this isn't a problem that's specific to Spring Boot and I think it needs to be addressed in Spring HATEOAS. Two possible solutions are:

  • Make HalHandlerInstantiator part of the supported API so that users can implement a delegating HandlerInstantiator as described above
  • Make it possible for Spring HATEOAS to be configured with a HandlerInstantiator that HalHandlerInstantiator will delegate to.

Unfortunately, GitHub doesn't allow me to move this issue to another repository. You may want to open a Spring HATEOAS issue. This existing issue may also be of interest. It appears that others are already writing code that depends on HalHandlerInstantiator and would benefit from it being part of the public API where backwards compatibility is maintained, etc.

@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 1, 2015
@countrogue
Copy link
Author

Ok thanks @wilkinsona

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants