-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
Make the new jackson version ignore default values #514
Comments
This behaviour is not currently configurable. One option to work around this would be to create your own version of ScalaAnnotationIntrospectorModule that omits the defaultValue code. |
@pjfanning Would you accept a PR to make this behavior configurable? In general very excited about getting the respect for default params, but am concerned for certain parts of our team's app. The problem case for us is mostly centered around a generic framework we use to power public apis. We do not explicitly serialize nulls and it operates on many business objects scattered throughout the app. I'm a little worried about not being able to effectively audit the thousands of case classes in our app for places where a previously benign default param might change some data in an unexpected way. The problem case I'm imagining would probably go something like this:
We have some case class that is compositionally included in many other objects. A feature change is introduced (perhaps a migration of some kind), along with a default parameter that previously would only be non-null upon the For a legacy version of this object, we expect this param to be None, as it has never been set before. We expect new instances of this class to have the flag / use the new behavior, but for older objects we need to run a migration script or in some other way prepare for flipping this flag. When Jackson Module Scala changes it's behavior, all of a sudden our expected, but non serialized nulls will be inadvertently overriden by the default param potentially landing us in hot water. Like I said, in general we are very excited about respecting default params on case classes as that is definitely what a programmer would expect, but being able to slowly opt parts of our app into this behavior would make these changes far more digestible. I think what would be ideal for our use case would be to be able to turn this setting off for the specific mapper that powers the aforementioned framework, then basically have it turned on anywhere else. I imagine there could be others in similar situations as well. Thanks, |
@nick-benoit14 PRs are always welcome - best targeted to the 2.13 branch. Would you be able to provide some ideas about the config mechanism you intend to use? jackson-module-scala is lacking configurability and it would be good to discuss solutions. |
@cowtowncoder would it be possible to add a JsonReadFeature to control if default values are applied when deserialising json? |
A new feature is a possibility, given that this could be something usable for other modules (Kotlin, and maybe even "plain" Java one eventually). But it could be either additional Downside of defining a general-purpose feature is just that it may be unclear where exactly it is applied (assuming other modules won't immediately start using it). Kotlin module is adding support for configuration via Builder for 2.13, for what that is worth; it might be worth considering for Scala module too. But I am open to all options. |
@cowtowncoder I think that the feature is useful for other modules (even if they don't implement support yet). My gut feeling is a DeserializationFeature would be the best way to go. One thing though, it might be best to make the feature something like DeserializationFeature.IgnoreDefaultValues so that by default - default values are used. Today, default values are supported by default and it would affect users if we forced them to opt in to keeping the feature enabled. |
@pjfanning I think to the point in the code where I understand how to make my desired change, but yeah not really sure how the configuration piece should work. I think that a DeserializationFeature would make sense as well. Can you shed any light on what the process of getting a new DeserializationFeature into core jackson looks like? |
So for testing you'd probably want to build |
Hi @pjfanning i'm having a hard time finding docs / figuring out how to build the jackson deps locally to test with my branch of jackson-scala-module. Are there any existing docs on that that can point me towards? |
Dependency you need wrt
and this would produce |
@nick-benoit14 #521 is one possible solution |
I opened: #527 Is that kind of what you had in mind @pjfanning? |
@nick-benoit14 we'll have to see if FasterXML/jackson-databind#3181 gets merged |
Added a note there. Will merge if:
|
Ah... Apologies for asking for (2), I had missed the part of this really just being changing behavior of existing functionality. So on (1): it looks like this may indeed be changed between calls, like so:
and if so It'd be good to have a unit test that verifies this, just in case. |
I was working on adding a test to make sure the above example worked. It does not work right now on my branch. It seems like maybe when you do |
@nick-benoit14 did you read my comment on your PR? could be related to your test issue too |
As long as check for setting occurs via But if |
Made changes to support (1), and I added a test for that behavior as well. The previous issue was that I was not checking the config in the null value provider, but rather in the class that created the null value provider. @pjfanning I saw your comment / made a change to address. Thanks! |
In 2.13.0-RC1, MapperFeature.APPLY_DEFAULT_VALUES will be supported - defaults to true.
|
Thanks @pjfanning. Are we good to go ahead and close out this issue then? |
thanks @nick-benoit14 - I'll close this now - the fix will be in the 2.13.0-RC1 release which should be released soon |
Hi guys, I tried to dig through the code and the documentation, but it was too difficult for me.
Is there a way to disable default values in the new jackson version?
Is there some kind of configuration for that?
The text was updated successfully, but these errors were encountered: