I have this simple Java Entity and I Need to make it JSon output, which I reach with e web service.
@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;}
I added @JsonRootName
, but I still get my json output in this way :
[
{
},
{
}
]
What more I have to add to my entity, so finally to get this kind of output:
{
"flights":
[
{
},
{
}
]
}