I have the following class:
@Entity
@Table(name = "Positions")
@NamedQuery(name = "Position.findAll", query = "SELECT p FROM Position p")
public class Position implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "id")
private Long id;
private String title;
private String description;
@ElementCollection
@CollectionTable(name = "qualifications", joinColumns = @JoinColumn(name = "position_id"))
@Column(name = "required_qualifications")
private List<String> requiredQualifications;
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinTable(name = "positions_competencies", joinColumns = @JoinColumn(name = "position_id"), inverseJoinColumns = @JoinColumn(name = "Competence_id"))
private List<Competence> competencies;
@ManyToOne
@JoinColumn(name = "department_id")
private Department department;
I'm using spring boot with spring data.
I want to ignore some of the fields in the getAllPositions
method, but not in the getPositionById
method, so @JsonIgnore
won't work for me. What is the best way to do this in Spring Boot 2.0.2?
Here is the controller:
@Autowired
private PositionRepository positionRepository;
@GetMapping(path = "/positions")
public Iterable<Position> getAllPositions() {
return positionRepository.findAll();
}
@GetMapping(path = "/positions/{id}")
public Position getPositionById(@PathVariable Long id) {
return positionRepository.findById(id).get();
}