Hello. There was a situation not quite clear to me: there is an essence
@Entity @Table(name = "trCompany") @JsonInclude(JsonInclude.Include.NON_NULL) public class TransportCompany implements Serializable, Storable { private static final long serialVersionUID = 1000000005645644L; @JsonProperty("id") @JsonView(Views.User.class) @Id @GeneratedValue(generator = "increment") @GenericGenerator(name = "increment", strategy = "increment") @Column(name = "id", nullable = false) private Long id; @JsonProperty("name") @JsonView(Views.User.class) @Column(name = "name", nullable = true, length = 150) private String name; @JsonProperty("phone") @JsonView(Views.User.class) @Column(name = "phone", nullable = true) private String phone; ... @Transient @JsonView(Views.User.class) private Collection<Orders> orderCollection; @Override public String toString() { return String.format("%d, %s, %s, %s;", id, name, phone, orderCollection); } ... } There are dao and services, and a view controller
@RestController public class TransportCompanyController { ..... @JsonView(Views.User.class) @PreAuthorize(value = "hasAnyRole('ROLE_ADMIN', 'ROLE_USER')") @RequestMapping(value = "/t/all", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getAll(){ List<TransportCompany> transportCompanyList = transportCompanyService.getAll(); System.out.println("TR-COMP: " + transportCompanyList.get(0).toString()); return ResponseEntity.status(HttpStatus.OK).body(transportCompanyList); } ... } And this is all wrapped up in spring-boot. In general, the problem is in the received JSON response, it looks like this:
[{"name":"Новая почта","phone":"+380671111111"},{...},{...}] and I, well, very, very much, need the answer to look like this, with ID :
[{"id":"1","name":"Новая почта","phone":"+380671111111"},{...},{...}] In general, something with the JSON representation is not that, although working with similarly described entities for other objects, but similar, objects and their controllers, respectively, work normally, i.e. the answer comes with the ID - as it should be ... Thanks in advance for the answer! PS / Just in case. Inside the controller there is System.out, everything is fine there ID - is present.