【发布时间】:2017-08-04 01:40:44
【问题描述】:
简化示例
我运行一个带有日期的本地查询:
SELECT id, start FROM event;
我做了一个 SqlResultSetMapping 像:
@SqlResultSetMapping(
name="EventMapping",
classes={
@ConstructorResult(
targetClass=de.teamsystems.domain.OverviewEvent.class,
columns={
@ColumnResult(name="id", type = Long.class ),
@ColumnResult(name="start", type = DateTime.class )
}
)
}
)
我的 OverviewEvent 类看起来像:
@Entity
public class OverviewEvent {
@Id
private Long id;
private String name;
private DateTime start;
public Long getId() {
return id;
}
public DateTime getStart() {
return start;
}
public OverviewEvent(Long id, DateTime start) {
this.id = id;
this.start = start;
}
}
当我在控制器中执行此代码时,出现以下异常:
{
"error": "Internal Server Error",
"exception": "javax.persistence.PersistenceException",
"message": "org.hibernate.type.SerializationException: could not deserialize",
"path": "/event",
"status": 500,
"timestamp": "2017-03-13T22:22:30.527+0100"
}
日志文件说:
2017-03-13 22:22:30.523 ERROR 23479 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.type.SerializationException: could not deserialize] with root cause
java.io.StreamCorruptedException: invalid stream header: 32303137
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:808) ~[na:1.8.0_111]
当我在 OverviewEvent 类和 SqlResultSetMapping 中将 DateTime 更改为 String 时,它可以工作。但我想使用日期时间格式。
有没有人可以帮助我解决这个例外。我尝试了不同的方法,例如:
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
private DateTime start;
但异常保持不变。感谢您帮助我。
【问题讨论】:
标签: java json jackson jodatime