2017-08-04 20 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") 

得到它的工作。