2017-08-04 43 views
0

我使用resteasy jakson提供3.0.17,這裏是我的對象結構。傑克遜3.0無法序列化與@EmbededId對象

@SuppressWarnings("serial") 
@Entity 
@Getter 
@Setter 
@EqualsAndHashCode 
@NoArgsConstructor 
@AllArgsConstructor 
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, 
     property = "@id") 
public class Product implements Serializable { 
    @Id 
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_seq") 
    @SequenceGenerator(name = "id_seq", sequenceName = "id_seq") 
    private Long productId; 

    @Basic 
    private String productName; 

    @Basic 
    private String type; 

    @Basic 
    private String productCode; 

    @Basic 
    private String outputName; 

    @Basic 
    private String creationMethod; 

    @LazyCollection(LazyCollectionOption.FALSE) 
    @OneToMany(mappedBy = "primaryKey.product") 
    @JsonManagedReference 
    private Set<ProductDataElement> productDataElements = new HashSet<>(); 
} 

@SuppressWarnings("serial") 
@Entity 
@Table(schema = "product", name = "productdataelement") 
// To cater to additional column in the mapping table 
@AssociationOverrides({ 
     @AssociationOverride(name = "primaryKey.product", joinColumns = @JoinColumn(name = "productId")), 
     @AssociationOverride(name = "primaryKey.dataElement", joinColumns = @JoinColumn(name = "dataElementId")), 
}) 
@Setter 
public class ProductDataElement implements Serializable { 
    @EmbeddedId 
    @JsonUnwrapped 
    private ProductDataElementId primaryKey; 

    @Basic 
    private Long rowLimit; 
} 

@SuppressWarnings("serial") 
@Getter 
@Setter 
@EqualsAndHashCode 
@NoArgsConstructor 
@AllArgsConstructor 
@Embeddable 
public class ProductDataElementId implements Serializable { 

    @JsonBackReference 
    @ManyToOne(cascade = CascadeType.ALL) 
    private Product product; 

    @JsonBackReference 
    @ManyToOne(cascade = CascadeType.ALL) 
    private DataElement dataElement; 

} 

當我做了一個特定產品JPA查詢,我得到服務器端的嵌套結構,其中包含productDataElements收集,但是當這個數據是通過REST Web服務調用發送到瀏覽器中,我得到收集與空對象ProductDataElement對象。任何線索什麼可能是獲得完整對象的可能解決方案?

回答

0

它現在已經得到解決..

我不得不對AADD和ProductDataElementId ProductDataElement

@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, 
     property = "@id") 

得到它的工作。