好吧,我正在使用 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
任何人都可以帮助我吗??