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

Is there any way to ignore @JsonAttribute(ignore = true) when serializing? #212

Open
mecoFarid opened this issue Jun 16, 2021 · 2 comments

Comments

@mecoFarid
Copy link

Is there any way to ignore @JsonAttribute(ignore = true) when serializing the Object?

Use-case:
A class is used for both sending the data to the server and local caching. Some fields must not be sent to a server but should be cached.

NOTE: I can do this with inheritance. "remote" and "cache" models would inherit the same class and have specific fields ignored with @JsonAttribute(ignore = true). The problem is inconsistency; e.g. any change (field addition or removal) in either of these child classes will result in indeterministic bugs

@zapov
Copy link
Member

zapov commented Jun 17, 2021

Not currently. It seems you want some runtime policy for field behavior. Which would be nice to have for some options, but there isn't one yet.

The closest you can get to this would be to send only non-null fields from server and manage the value of those via custom formatter.

@mecoFarid
Copy link
Author

mecoFarid commented Jun 17, 2021

The closest you can get to this would be to send only non-null fields from server and manage the value of those via custom formatter.

The thing is I'm trying to avoid customization for two exact reasons:

  1. Bugs; Future changes in class would require more customizations and if forgotten may lead to bugs
  2. Verbosity; Current models even have other classes as members which have more fields annotated with @JsonAttribute(ignore = true)

It seems you want some runtime policy for field behavior.

Actually, I was thinking about an option to build DslJson instance that would keep fields even if they're annotated with @JsonAttribute(ignore = true). This would eliminate the need for a runtime policy, I think. But with the current implementation, this seems unlikely because anything annotated with @JsonAttribute(ignore = true) is excluded from Converters

Thanks for the reply

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

No branches or pull requests

2 participants