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(access = Access.READ_ONLY) - unexpected behaviour

See original GitHub issue

Hey,

I was hoping to make use of @JsonProperty(access = Access.READ_ONLY), but failed.

Assume this class:

public class TestPojo
{
    private String firstName;

    private String lastName;

    @JsonProperty(access = Access.READ_ONLY)
    public String getFullName()
    {
        return firstName + " " + lastName;
    }

    public String getFirstName()
    {
        return firstName;
    }

    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }
}

I couldn’t find a way to stop the deserializer from attempting to deserialize the field “fullName”. The only thing that helps is to create a setter and annotate it with @JsonIgnore. However, that setter does not make sense and I don’t want to have it. Is this a bug in behaviour or am I missing something? Thanks

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:4
  • Comments:29 (14 by maintainers)

github_iconTop GitHub Comments

6reactions
mewertcommented, Feb 2, 2016

Hi,

is there some easy workaround, until this is fixed? I mean instead of implementing a noop setter method?

The annotation @JsonIgnoreProperties sounds like it could help here. But it also has no effect, if I add it to a getter, regardless which values I choose for allowGetters or allowSetters.

Update: It seems that I found a solution by adding

@JsonIgnoreProperties(value="some_field", allowGetters = true, allowSetters = false)

to the class. So this could be a solution, if we don’t need the @JsonIgnoreProperties annotation on class level for other purposes.

2reactions
cowtowncodercommented, Aug 9, 2019

Also: my earlier explanation was exactly backwards. Javadocs state it correctly (if not well): READ_ONLY refers to POJO being handled in read-only way, and WRITE_ONLY opposite. So Java-centric, not JSON-centric.

I really should have named values differently (GETTER_ONLY, SETTER_ONLY, perhaps).

Read more comments on GitHub >

github_iconTop Results From Across the Web

JsonProperty(access = JsonProperty.Access.WRITE_ONLY ...
It seems this unexpected behaviour is a bug (see ... adapted to mimic the intended behaviour of the @JsonProperty(access = JsonProperty.
Read more >
JsonProperty.Access (Jackson-annotations 2.6.0 API)
Access setting that means that the property may only be read for serialization, but not written (set) during deserialization. WRITE_ONLY. public static final ......
Read more >
Management & Monitoring - Micronaut Documentation
The Netty access logger now supports excluding requests based on a set of regular expression ... This is an important behavioural change from...
Read more >
Breaking changes in EF Core 5.0 - Microsoft Learn
The following API and behavior changes have the potential to break ... However, in cases where the navigation is used to access foreign...
Read more >
KEPServerEX Manual - Kepware
Configuration session assigned to <name> promoted to write access. 282. Configuration session assigned to <name> demoted to read only.
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