Read-only and write-only properties (Jackson2, JSDoc tags) #579
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When communicating using JSON objects over HTTP usually most of the properties are sent in both directions (GET vs. POST, PUT). But sometimes some properties are sent only from server to client and others are sent only from client to server. Classical example can be following REST object:
In this example when client application is creating new
User
it sendsname
andpassword
properties then server generatesid
property and returnsUser
object containingid
andname
properties. As you can see Jackson2 library allows us to mark properties read-only or write-only using@JsonProperty
annotation.This PR provides possibility to leverage Jackson2 support for read-only and write-only properties and generate for example following TypeScript declaration:
This feature is turned off by default and can be turned on using
generateReadonlyAndWriteonlyJSDocTags
parameter.Read-only and write-only properties can be used not only for real read-only or write-only properties like in
id
andpassword
example but we can also have resource object where some property has different "shape" when it is read or written by client. For example we can have logical propertyusers
(access control list) which is sent in "expanded" form by server but client sends just user IDs:Currently this feature is limited to Jackson2 library (input) and JSDoc tags (output) but it can be expanded in the future.