Skip to content
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

Fail on unknown property overridden by ConverterRegisteringWebMvcConfigurer > createHalConverter #765

Open
ghost opened this issue Dec 13, 2018 · 7 comments

Comments

@ghost
Copy link

ghost commented Dec 13, 2018

Hello,
I have
spring.jackson.deserialization.fail-on-unknown-properties=true

But in the ConverterRegisteringWebMvcConfigurer > createHalConverter

there is
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

The question
Is there an option to enable FAIL_ON_UNKNOWN_PROPERTIES ?

@gregturn
Copy link
Contributor

Why would you want to do this? It would break your ability to support backwards compatibility with RESTful services.

@ghost
Copy link
Author

ghost commented Dec 14, 2018

Yes and no.
In the case which you mentioned - it makes sense. But for all monolith apps where a strict JSON contract should be enforced (also my case) - it does not.

It would be nice if you have application.settings variable which can force this value to true.

 @Value("${spring.something.something:#{true}}")
 private String enforceFailOnUnknownProperties;

........................................................

ObjectMapper mapper = objectMapper.copy();
if(enforceFailOnUnknownProperties){
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
mapper.registerModule(new Jackson2HalModule());

@ghost
Copy link
Author

ghost commented Dec 18, 2018

Any idea if this feature is going to be added in the next releases ?

@gregturn
Copy link
Contributor

Included in the next release? Not likely. I'm not yet sold on this when discussing RESTful concepts.

If you need a workaround, you can always supply your own ObjectMapper and then apply a BeanPostProcessor after Spring HATEOAS has configured it.

@ghost
Copy link
Author

ghost commented Dec 20, 2018

@gregturn OK, it seems you restrict people from choosing another option, from the one you are enforcing.

An additional setting will make this choice a bit more "open" and flexible and it will fit wide variety of use cases.

It is just fixing something so small takes so much actions from the dev side (custom ObjectMapper and BeanPostProcessor). And by just adding a property you can solve that with an ease.

@gregturn
Copy link
Contributor

It’s strange to dub this as a “restriction” given we are talking about Postel’s law.

We are building a toolkit aimed at REST, not contract enforcement.

We can’t add 50 knobs to accommodate every desired hook into Jackson. It would make our API hard to use. At that point why use this toolkit?

So what is the threshold for a good knob vs. one too many?

@ghost
Copy link
Author

ghost commented Dec 27, 2018

As far as I know Spring and most of add-on projects has auto config (as the case here).

But at the same time there is easy way to "plug" yourself in and do small corrections to the default behaviour. Implement an interface, extend class or change application.properties.

If you consider my request as "it does't really makes sense", it would be really helpful if you add a code snippet for achieving the mentioned functionality. There are few stackoverflow questions about that topic.

Thank you in advance.

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

1 participant