【发布时间】:2016-07-18 09:42:53
【问题描述】:
我收到一个错误 - “类 com.fasterxml.jackson.datatype.joda.deser.DateTimeDeserializer 没有默认(无 arg)构造函数”,而我正在尝试为发布请求调用 restangular。当我调用该方法时,它会进入错误块。
Restangular.all('tests').post($scope.test).then(function (data) {
$scope.test.id = data.id;
$location.path($location.path() + data.id).replace();
}, function (error) {
$scope.exceptionDetails = validationMapper(error);
});
我正在使用 jackson-datatype-joda - 2.6.5
该方法中使用的实体类如下-
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@Entity
@Table(name = "Test")
@EqualsAndHashCode(of = "id", callSuper = false)
@ToString(exclude = {"keywords", "relevantObjectIds"})
public class Test {
@Id
@Column(unique = true, length = 36)
private String id;
@NotBlank
@NotNull
private String name;
@Transient
private List<Testabc> Testabcs = new ArrayList<>();
}
上述实体Testabc类中使用的实体类如下
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@Slf4j
@Entity
@Table(name = "Test_abc")
@EqualsAndHashCode(of = "id", callSuper = false)
public class Testabc{
@Id
@Column(unique = true, length = 36)
@NotNull
private String id = UUID.randomUUID().toString();
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@JsonDeserialize(using = DateTimeDeserializer.class)
@JsonSerialize(using = DateTimeSerializer.class)
private DateTime createdOn;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "Id")
@NotNull
private t1 pid;
private long originalSize;
}
最后是我请求创建测试数据的资源类 -
@ApiOperation(value = "Create new Test", notes = "Create a new Test and return with its unique id", response = Test.class)
@POST
@Timed
public Test create(Test newInstance) {
return super.create(newInstance);
}
我已经尝试添加这个 @JsonIgnoreProperties(ignoreUnknown = true) 在实体类上注解,但是不起作用。
谁能帮忙解决这个问题?
【问题讨论】:
-
不,没有重复
-
这是否意味着链接问题的答案和
mapper.registerModule(new JodaModule());的建议解决方案对您不起作用? -
此链接 (stackoverflow.com/questions/36795151/…) 建议使用注释或上述帮助,我只想使用注释来完成这项工作。我需要使用 mapper.registerModule(new JodaModule());带注释?
-
两种解决方案都表明
DateTimeDeserializer没有无参数构造函数,这确实是您的问题。如果您只想使用注释,您可以简单地自己扩展它并添加一个无参数构造函数,该构造函数使用必要的参数调用super。
标签: java angularjs spring nhibernate-mapping