Tom Taylor
Tom Taylor

Reputation: 3560

How to handle the following case with katharsis?

I have a model and repository. Model has getter and setter values which has to be added in the response. My model is like follows

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.katharsis.resource.annotations.JsonApiId;
import io.katharsis.resource.annotations.JsonApiResource;

@JsonApiResource(type="employee") //no i18n
public class Employee { 

    @JsonApiId
    private String name;
    private int emp_id;
    private String dob;

    private String profile_url;

    private String status_message;

    public String getName() {
          return this.name;
    }
    public void setName(String name) {
          this.name = name;
    }

    public int getEmp_id() {
          return this.emp_id;
    }
    public void setEmp_id(int empid) {
          this.emp_id = empid;
    }

    public String getDob() {
          return this.dob;
    }
    public void setDob(String dob) {
          this.dob = dob;
    }

    public String getProfile_url() {
          return this.profile_url;
    }
    public void setProfile_url(String url) {
          this.profile_url = url;
    }

    public String getStatus_message() {
          return this.status_message;
    }
    public void setStatus_message(String message) {
          this.status_message = message;
    } 
 }         

Here the variable status_message represents my api status. The api response should be like

  1. When the database has the employee with inputted id

{name : "rajasuba", emp_id : "123", dob : "March301993", profile_url : "https:", status_message : "success"}

  1. When the employee left the organization the response should be like

{name : "rajasuba", emp_id : "567", status_messsage : "fired"}

  1. When there is no such employee then my response should be like

{status_message : "Invalid employeed id"}

But for all the above cases i am getting all the attribute values. How can i ignore the attribute value (like @JsonIgnore) selectively for a particular scenario?

Upvotes: 0

Views: 384

Answers (1)

Christian Bongiorno
Christian Bongiorno

Reputation: 5648

I don't know what version of katharsis you're using, but in 2.8.2 it's supported

Upvotes: 1

Related Questions