katharsis-project / katharsis-framework

Katharsis adds powerful layer for RESTful endpoints providing implementenation of JSON:API standard
http://katharsis.io
Apache License 2.0
135 stars 65 forks source link

katharsis-jpa should respect @JsonIgnore #258

Open Ramblurr opened 7 years ago

Ramblurr commented 7 years ago

Currently the isIgnored method in JpaResourceInformationBuilder is not fully implemented:

  protected boolean isIgnored(MetaAttribute attr) {
        return false;
    }

It should be implemented to detect fields that should be ignored.

@JsonIgnore is the best candidate when it comes to existing annotations.

Optionally a new katharsis-jpa specific annotation could be used, but I don't think that is the best choice.

I'd implement this myself, but I got lost in the maze of Meta* classes. I couldn't see how to access the annotations via a MetaAttribute reference.

Ramblurr commented 7 years ago

Remo @remmeier 16:45 I would say the attribute should not be created in the first place. MetaDataObjectImpl.initAttributes is the place to prevent that.

chb0github commented 7 years ago

I am all for reusing @JsonIgnore

On Thu, Dec 15, 2016 at 8:41 AM Casey Link notifications@github.com wrote:

Remo @remmeier https://github.com/remmeier 16:45 I would say the attribute should not be created in the first place. MetaDataObjectImpl.initAttributes is the place to prevent that.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/katharsis-project/katharsis-framework/issues/258#issuecomment-267376320, or mute the thread https://github.com/notifications/unsubscribe-auth/ABaI0Cgq3W-28Q-EaNW48L97xKRRqePVks5rIW3AgaJpZM4LOPEY .

exports commented 7 years ago

Any update on this? I'm trying to modify isIgnored() but then I discovered it simply ignore both the getter and setter, which is not what I want (I have a password field that should only allow setter exposed to the api)

Ramblurr commented 7 years ago

What you're looking for is a write-only field, and there currently isn't a way to implement that with the API.

This ticket is about ignoring internal fields entirely (the whole field, both getter and setter).

In our katharsis project we work around this by having an empty getter/setter on our resource objects for read/write only fields respectively.

This only works because our katharsis resources are DTOs that are mapped onto JPA entities.