【发布时间】:2016-07-06 13:49:44
【问题描述】:
我有这个简单的 Java 实体,我需要将其设为 JSon 输出,我可以通过 e Web 服务访问它。
@Entity
@JsonRootName(value = "flights")
public class Flight implements Serializable {
@Transient
private static final long serialVersionUID = 1L;
public Flight() {
super();
}
public Flight(FlightDestination destinationFrom, FlightDestination destinationTo, Integer flightPrice, Date date,
Airplane airplaneDetail) {
super();
this.destinationFrom = destinationFrom;
this.destinationTo = destinationTo;
this.flightPrice = flightPrice;
this.date = date;
this.airplaneDetail = airplaneDetail;
}
public Flight(FlightDestination destinationFrom, FlightDestination destinationTo, Integer flightPrice, Date date) {
super();
this.destinationFrom = destinationFrom;
this.destinationTo = destinationTo;
this.flightPrice = flightPrice;
this.date = date;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Enumerated(EnumType.STRING)
private FlightDestination destinationFrom;
@Enumerated(EnumType.STRING)
private FlightDestination destinationTo;
private Integer flightPrice;
@Temporal(TemporalType.DATE)
private Date date;
@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
@JoinColumn(name = "airplane_fk")
private Airplane airplaneDetail;}
我添加了@JsonRootName,但我仍然以这种方式获得我的 json 输出:
[
{
},
{
}
]
我还有什么要添加到我的实体,所以最终得到这种输出:
{
"flights":
[
{
},
{
}
]
}
【问题讨论】:
标签: json jakarta-ee jackson