public class MyBean extends Model {
private String name;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
何时
List<MyBean> myBean = MyBean.find.all();//will return BeanList<Device>
JSONArray myBeanJsonList = new JSONArray(myBean);
或
JsonNode myBeanList = Json.toJson(myBean);
比在BeanList上循环花费更多时间并在ArrayList中添加Object
List<MyBean> myBean = MyBean.find.all();//will return BeanList<Device>
List<MyBean> myBeanList = new ArrayList<Device>();
for(MyBean d : myBean)
{
MyBean myBeanTemp = new MyBean();
myBeanTemp.setName(d.getName());
myBeanList.add(myBeanTemp);
}
JSONArray myBeanJsonList = new JSONArray(myBeanList);
或
JsonNode myBeanJsonList = Json.toJson(myBeanList);
是正常行为吗?