I have the following projection written for an entity class.
@Projection(name = "instituteProjection", types = { Institute.class })
public interface InstituteProjection {
String getOrganizationName();
Address getRegisteredAddress();
}
Now I am trying to apply this projection whenever I call the url http://localhost:8080/institutes/1?projection=instituteProjection
which returns a single institute resource. The controller GET method implementation is as follows:
@RequestMapping(value = "institutes/{instituteId}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getInstitute(@PathVariable Long instituteId) {
Institute institute = service.getInstitute(instituteId);
return new ResponseEntity<>(institute, HttpStatus.OK);
}
The problem is this does not return the institute projection. It returns the default repository json.
The projection only works if I use the SDR generated controller instead of the custom rest controller I have implemented.
So how do I apply the projection in the custom controller?
UPDATE 1 Institute class
@Data
@Entity
public class Institute{
private String organizationName;
@OneToOne
private Address registeredAddress;
@OneToOne
private Address mailingAddress;
}
UPDATE 2
Address class
public class Address {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private long addressID;
@ManyToOne
private Street street;
@ManyToOne
private Country country;
private double latitude;
private double longitude;
@ManyToOne
private City city;
}