我正在使用Hibernate来加载一个小型数据库到一些代表表格的类中,并与数据库进行交互。一切都很好,我真的可以看到所有结果...而且我没有任何空字段,它们都被使用了。
这里我展示了“主”类(表)。
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonProperty;
@JsonAutoDetect
public class Advertisement {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public int id;
public SessionT session;
public int idRoom;
public String image;
public Advertisement() {
}
/* Getters and Setters */
@JsonProperty
public int getID() /* Get example */ {
return this.id;
}
}
并且
@JsonAutoDetect
public class SessionT {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public int id;
public int iStatus;
public String sStatus;
public Date dtDateStart;
public Date dtDateEnd;
public boolean bhide;
/* Constructor, Getter and Setters*/
}
我的目标是从广告的列表中生成JSON并通过Http发送。
ObjectMapper mapper = new ObjectMapper();System.out.println("mapper started!");
mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
response.getOutputStream().println(mapper.writeValueAsString(ads));
因为某些原因,我遇到了以下错误:
org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.ArrayList[0]->entities.slave.Advertisement["session"]->entities.slave.SessionT_$$_javassist_2["hibernateLazyInitializer"])
我正在使用jackson-all-1.9.11和JBoss Studios 6.01。有人能帮助我吗?