conjure-java icon indicating copy to clipboard operation
conjure-java copied to clipboard

Provide a way to consider unknown union types invalid

Open maciekf opened this issue 7 years ago • 4 comments

Currently Jackson object mapper will happily deserialize an object with bogus union types. This is desirable in certain cases as it allows for additive changes. However, on the server side quite often we want to discard such objects.

maciekf avatar Oct 02 '18 16:10 maciekf

Why can't you handle to UNKNOWN case explicitly in your code?

uschi2000 avatar Oct 02 '18 16:10 uschi2000

It's not a blocker, I can just generate a visitor and handle it explicitly.

However, the overhead is significant especially if that is the only validation one wants to perform on an object. In addition to that, the current behavior is error-prone as the validation has to be added every time new union is introduced.

maciekf avatar Oct 02 '18 19:10 maciekf

For Java consumers, the expectation is that any union type is accessed through the visitor and you are explicitly forced to handle UNKNOWN by implementing the visitor. This is still true when a new union member is introduced.

uschi2000 avatar Oct 02 '18 19:10 uschi2000

That's true. The problem arrises if a server does not need to use the union on put but it needs to do something with it on get. In such case one has to implement 2 visitors which is quite verbose.

maciekf avatar Oct 03 '18 09:10 maciekf