question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@JsonProperty() in getters

See original GitHub issue

Is it possible to add @JsonProperty decorator to a getter function?

@Serializable()
class MyClass {
  @JsonProperty()
  get myProperty(): string { return this.myProperty }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pablomartinezmcommented, Jan 8, 2021

Of course in this example does not make sense, but as soon as we have domain models and we want it to serialize them hierarchically to convert them to DTOs it is really handful to have this functionality:

@Serializable()
export class User {
    constructor(private props: UserProps { }
    @JsonProperty()
    get id(): Id {
        return this.props.id;
    }
    @JsonProperty()
    get name(): string {
        return this.props.name;
    }
}

@Serializable()
export class TestEntity {
    constructor(private props: TestEntityProps) { }

    @JsonProperty()
    get users(): User[] {
        return this.props.is;
    }
}
0reactions
stale[bot]commented, Feb 7, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JsonProperty annotation on field as well as getter/setter
The purpose is so that when the object is serialized using the Jackson library, the fields have that specific name.
Read more >
JsonProperty (Jackson-annotations 2.9.0 API) - FasterXML
Marker annotation that can be used to define a non-static method as a "setter" or "getter" for a logical property (depending on its...
Read more >
Jackson JSON - Using @JsonProperty, @JsonSetter and ...
Following example shows how to use @JsonProperty annotation to rename properties. This annotation can be used on fields or getters or setters.
Read more >
Jackson Annotations - @JsonProperty - Tutorialspoint
@JsonProperty is used to mark non-standard getter/setter method to be used with respect to json property. Example - @JsonProperty. import java.io.
Read more >
About @JsonProperty, @JsonGetter and @JsonSetter
@JsonProperty: Marker annotation that can be used to define a non-static method as a "setter" or "getter" for a logical property (depending on ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found