Skip to content

Add support for new property of @JsonProperty to support read-only/write-only use cases #813

@cowtowncoder

Description

@cowtowncoder

Although it is possible to support read-only/write-only use cases with a combination of various settings, like visibility settings, and/or addition of setters/getters, it would be useful to just have a property that dictates intended behavior, like:

  • read-only: figure out an accessor (getter or field), regardless of visibility; ignore any mutators
  • write-only: figure out a mutator (getter, field, creator parameter), regardless of visibility, ignore any accessors
  • read-write: figure out both accessor and mutator, if any found, regardless of visibility:
  • auto: just use default visibility settings (current behavior)

and default to auto for backwards compatibility.

The benefit here is that this basically allows overriding of visibility settings for individual properties.

For example:

  • For a password field, we may want "write-only" behavior, so that password is never exposed on serialization, but may be passed in via deserialization
  • Certain settings are not to be used via POJO, but should be included in serialization: read-only setting would allow use of private accessor or field for serialization, without having to change visibility settings, or make getter public
  • Modules that want to change default behavior of certain special classes could specify one of accessor cases (like read-write) to enable convenient round-trip behavior (for example, Scala module could do this at least for case classes, maybe all typical Scala beans).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions