dsl-json icon indicating copy to clipboard operation
dsl-json copied to clipboard

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

Open mecoFarid opened this issue 3 years ago • 2 comments

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

mecoFarid avatar Jun 16 '21 15:06 mecoFarid

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.

zapov avatar Jun 17 '21 06:06 zapov

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

mecoFarid avatar Jun 17 '21 10:06 mecoFarid