迁移到 Spring Boot 2.2.0,所有带有 @JsonIgnore
注释的属性现在都在 API Rest Body 中序列化(而在 Boot 2.1.9 中工作正常)。
此外,在每个嵌套对象之前添加了一个 "_embedded"
属性。
这似乎是 jackson 的问题。
代码详情:
@Entity
@Audited
@Data
@EqualsAndHashCode(callSuper = true, of = { "makeId", "modelId", "versionId", "bodyTypeId", "modelYear" })
@ToString(callSuper = true, of = { "makeName", "modelName", "versionName", "bodyTypeId", "modelYear" })
@NoArgsConstructor
@RequiredArgsConstructor
@Table(schema = "fleet", name = "vehicles", uniqueConstraints = { @UniqueConstraint(columnNames = { "id", "make_id", "model_id", "version_id", "body_type_id", "model_year", "port_number" }) })
public class Vehicle extends BaseEntity implements VehicleBaseMakeInfo {
@OneToMany(mappedBy = "vehicleRef", cascade = CascadeType.DETACH, orphanRemoval = false, fetch = FetchType.LAZY)
@JsonIgnore
private Set<Car> cars = new HashSet<>();
@Length(max = 250)
@Column(name = "make_id", length = 250)
private String makeId; // UK_1
@Length(max = 250)
@Column(name = "make_name", length = 250)
@NonNull
@NotBlank
private String makeName;
@Length(max = 250)
@Column(name = "model_id", length = 250)
private String modelId;
...
一旦我执行 GET 请求“http://localhost:8081/api/vehicles”
我收到了
{
"id": 105,
"state": "ACTIVE",
"enabled": true,
"avatarDocumentId": null,
"makeId": "Bmw",
"makeName": "Bmw",
"modelId": "X4",
"modelName": "X4",
"modelNameOriginal": null,
"versionId": "Executive",
"versionName": "Executive",
"bodyTypeId": "Wagon",
"engineCapacity": 2.0,
"fuelingId": "Unleaded",
"power": 184.0,
"co2": 2,
"detailedTransmissionId": "Manual",
"tractionName": "4x4",
"portNumber": 3,
"urbanCycle": 4.3,
"extraUrbanCycle": 3.8,
"mixedCycle": 4.0,
"price": 27000.0,
"annualFringeBenefit": null,
"fringeCustomValue": false,
"modelYear": 2016,
"sourceType": "CUSTOM",
"inProduction": true,
"fringeAlgMatchingState": null,
"fringeMatchingCorrection": null,
"requiredReviewType": null,
"fringeSimilarVehicleId": null,
"useType": "PASSENGER_TRANSPORT",
"correctToCreateAsNew": false,
"productionStartDate": null,
"productionEndDate": null,
"calculatedMonthFringeBenefit": null,
"fullVersionExtended": "Bmw X4 Executive Wagon 3p 4x4 Unleaded 2016",
"calculatedAnnualFringeBenefit": null,
"objectId": "105",
"_embedded": {
"cars": [
{
"id": 258,
"state": "INSTALLED",
"enabled": true,
"avatarDocumentId": null,
"contractVersions": [
{
"id": 308,
"state": "ACTIVE",
如您所见,“_embedded”和“cars”不应出现。 在升级到 Boot 2.2.0 之前它工作正常
谢谢
安东尼奥
最佳答案
升级到Spring Boot 2.2.1 问题解决
关于spring - 迁移到 Spring Boot 2.2.0 @JsonIgnore 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58648267/