how to exclude a property in Olingo Odata4 java spring boo in response? For example in the below example need to exclude "details" property in the response
//Employee.java
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(schema="EMPLOWNER", name="EMPLOYEE")
public class Employee{
private String empId;
private String empName;
// Need to exclude in response with an annotation
private String details;
}
Below is the code for setting CsdlProperty using Olingo:
EmployeeCsdlEntityType.java
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
import org.apache.olingo.commons.api.edm.provider.CsdlEntityType;
import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
import org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef;
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
public class EmplCsdlEntityType implements ICsdlEntityType{
@Override
public CsdlEntityType getCsdlEntityType(EntityDetailEnum entityDetailEnum){
CsdlProperty empId=new CsdlProperty().setName("empId").setType(EdmPrimitiveTypeKind.String.getFullQulifiedName());
CsdlProperty empName=new CsdlProperty().setName("empName").setType(EdmPrimitiveTypeKind.String.getFullQulifiedName());
CsdlProperty details=new CsdlProperty().setName("details").setType(EdmPrimitiveTypeKind.String.getFullQulifiedName());
CsdlPropertyRef propRef=new CsdlPropertyRef();
propRef.setName("Id");
CsdlEntityType entityType=new CsdlEntityType();
entityType.setName(entityDetailEnum.getEntityType());
entityType.setProperties(Arrays.asList(empId,empName,details))
entityType.setKey(Collections.singletonList(propertyRefOwner));
return entityType;
}
}
I could able to solve this issue by creating custom annotation and validating the annotation: