У меня есть объект Квартира:
@Entity
public class Apartment extends AbstractEntity {
private String name;
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(nullable = false)
@RestResource(exported = false)
private Address address;
private String website;
@OneToMany(mappedBy = "apartment")
@RestResource(exported = false)
private Set<FloorPlan> floorPlans;
...
Объект FloorPlan:
@Entity
public class FloorPlan extends AbstractEntity {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "apt_id", nullable = false)
private Apartment apartment;
private float bed;
private float bath;
private int priceFrom;
...
Я применил отрывок проекции к Плану этажа, чтобы показать только кровать, ванну и цену от.Когда я запрашиваю коллекцию квартир, вывод json выглядит нормально:
{
"_embedded": {
"apartments": [
{
"name": "Avalon Silicon Valley",
"website": "https://www.avaloncommunities.com/california/sunnyvale-apartments/avalon-silicon-valley",
"address": {
"streetNumber": "1257",
"street": "Lakeside Drive",
"city": "Sunnyvale",
"state": "CA",
"zipCode": "94085",
"fullAddress": "1257 Lakeside Drive, Sunnyvale, CA 94085"
},
"floorPlans": [
{
"bed": 3,
"bath": 3,
"priceFrom": 4495
},
{
"bed": 3,
"bath": 2,
"priceFrom": 4760
},
Однако, если я сделаю один ресурс, такой как http://localhost:8080/ag-api/apartments/1, этажи будут отображать Apartment Object как одно из его полей:
{
"name": "Avalon Silicon Valley",
"address": {
"streetNumber": "1257",
"street": "Lakeside Drive",
"city": "Sunnyvale",
"state": "CA",
"zipCode": "94085",
"fullAddress": "1257 Lakeside Drive, Sunnyvale, CA 94085"
},
"website": "https://www.avaloncommunities.com/california/sunnyvale-apartments/avalon-silicon-valley",
"floorPlans": [
{
"bed": 3,
"bath": 3,
"priceFrom": 4495,
"_embedded": {
"apartment": {
"name": "Avalon Silicon Valley",
"website": "https://www.avaloncommunities.com/california/sunnyvale-apartments/avalon-silicon-valley",
"address": {
"streetNumber": "1257",
"street": "Lakeside Drive",
"city": "Sunnyvale",
"state": "CA",
"zipCode": "94085",
"fullAddress": "1257 Lakeside Drive, Sunnyvale, CA 94085"
},
"floorPlans": [
Кто-нибудь понял, что может происходить?действительно ценю это.Спасибо