0
Bu basit Java Varlığına sahibim ve e-web hizmeti ile ulaştığım JSon çıktısını almam gerekiyor.@JsonRootName çalışmıyor
@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;}
Ben @JsonRootName
eklendi, ama hala bu şekilde benim json çıktısı almak: çıktı bu tür almak çok nihayet, daha benim varlığa eklemek zorunda Ne
[
{
},
{
}
]
:
{
"flights":
[
{
},
{
}
]
}
olacak Bu kod hizmetimde ise sadece uçuşların listesini döndürüyorum (Liste) –
user5783530
Bence, hangi JavaEE çerçevesini kullandığınıza bağlı. Burada Bahar ise daha fazla bilgi https://docs.spring.io/spring/docs/3.2.x/javadoc-api/org/springframework/http/converter/json/JacksonObjectMapperFactoryBean.html veya http: // stackoverflow. com/questions/14343477/nasıl yapılır-global-set-jackson-ignore-bilinmeyen-özellikleri-içinde bahar – varren
@ user5783530 Ben sadece fark, 'JsonRootName' size yardımcı olamaz. Cevabımı güncellendi – varren