【发布时间】:2011-09-09 11:58:02
【问题描述】:
我试图通过 renderJson() 在我的模型中公开一个动态(瞬态)字段,但它不起作用。这是一个例子:
@Entity
public class Room extends Model {
public String name;
public String code;
@Transient
public List<Booking> bookings;
@Transient
@Expose
public String resource_uri;
public Room(String name, String code) {
this.name = name;
this.code = code;
}
public List<Booking> getBookings() {
return Booking.find("byRoom", this).fetch();
}
public String getResource_uri(){
return "/api/room/" + this.id; //the uri is evaluated dynamically.
}
调用 renderJson(Room.findById(2)) 将其呈现为响应:
{"name":"Room B","code":"R-B","id":2}
缺少 resource_uri 字段。 @Expose 注释似乎什么都不做。而且我无法查看renderJson的声明,因为框架通过注释生成所有代码。
【问题讨论】:
标签: java json annotations playframework gson