Я использую Spring Boot 2.2, Spring Data REST, Spring HATEOAS. Я сталкиваюсь со странной проблемой. У меня есть RestController, принимающий этот объект:
@Data
public class DocumentJSON {
@Valid
private Document document;
private List<DocumentRow> rows = new ArrayList<>();
private List<DocumentVat> vats = new ArrayList<>();
private Set<DocumentPayment> payments = new HashSet<>();
private boolean updateContactDetail = false;
}
и DocumentPayment
:
@Data
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true)
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString(callSuper = true)
public class DocumentPayment extends AbstractEntity {
@ToString.Exclude
@JsonDeserialize(using = DocumentUriDeserializer.class)
@NotNull
@OnDelete(action = OnDeleteAction.CASCADE)
@ManyToOne(fetch = FetchType.LAZY, optional = false)
private Document document;
@NotNull
@Column(nullable = false, columnDefinition = "DATE")
private Instant date;
//Optional contact (the receipt has not a contact)
@ToString.Exclude
@ManyToOne(fetch = FetchType.LAZY)
private Contact contact;
@NotBlank
@Column(nullable = false)
private String description;
@ToString.Exclude
@JsonDeserialize(using = FinancialAccountUriDeserializer.class)
@NotNull(message = "{documentpayment.financialaccount.missing}")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
private FinancialAccount financialAccount;
@Enumerated(EnumType.STRING)
@NotNull
@Column(nullable = false, length = 30)
private PaymentType paymentType;
//The amount, negative for payment to suppliers
@NotNull
@ColumnDefault("0.00")
@Column(nullable = false, scale = 2, columnDefinition = "DECIMAL(12,2)")
private BigDecimal amount = BigDecimal.ZERO;
//The amount paid
@NotNull
@ColumnDefault("0.00")
@Column(nullable = false, columnDefinition = "DECIMAL(12,2)")
private BigDecimal paid = BigDecimal.ZERO;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@Generated(value = GenerationTime.ALWAYS)
@Column(columnDefinition = "DECIMAL(12,2) AS (amount-paid) VIRTUAL NOT NULL")
private BigDecimal due;
@ToString.Exclude
@JsonDeserialize(using = StoreUriDeserializer.class)
//@NotNull(message = "{documentpayment.store.missing}")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "store_id", updatable = false)
private Store store;
}
Клиент отправляет Json следующим образом:
{
"document": {
"date": "2019-10-18T00:00:00.000Z",
"type": "SALES_RECEIPT",
"store": "http://95.255.117.252:8082/api/v1/stores/1",
"rounding": 0,
"amount": 19.23,
"taxAmount": 0.77,
"totalAmount": 20
},
"rows": [
{
"index": 1,
"productType": "FRAME",
"qty": 1,
"rowGroup": null,
"unitPrice": 9.615,
"percentageDiscount": 0,
"purchaseUnitPrice": null,
"amount": 9.615,
"description": "Prodotto1",
"taxRate": "http://95.255.117.252:8082/api/v1/taxRates/2",
"note": false
},
{
"index": 1,
"productType": "OPHTHALMIC_LENS",
"qty": 1,
"rowGroup": null,
"unitPrice": 9.615,
"percentageDiscount": 0,
"purchaseUnitPrice": null,
"amount": 9.615,
"description": "Lente",
"taxRate": "http://95.255.117.252:8082/api/v1/taxRates/2",
"note": false
}
],
"payments": [
{
"date": "2019-10-18T00:00:00.000Z",
"financialAccount": "http://95.255.117.252:8082/api/v1/financialAccounts/1",
"paymentType": "CASH",
"amount": "10"
},
{
"date": "2019-10-18T00:00:00.000Z",
"financialAccount": "http://95.255.117.252:8082/api/v1/financialAccounts/3",
"paymentType": "CREDIT_CARD",
"amount": "10"
}
],
"updateContactDetail": false
}
но когда я отлаживаю в первой строке контроллера REST, я вижу только 1 платеж.
При изменении платежей за собственность в DocumentJSON
с Set<DocumentPayment>
на List<DocumentPayment>
, я получаю 2 платежа, как и ожидалось стот же JSON.
Я что-то упустил или Спринг / Джексон не в состоянии правильно десериализовать набор <>?