当我尝试使用restangular进行post请求时,出现了以下错误 -“Class com.fasterxml.jackson.datatype.joda.deser.DateTimeDeserializer没有默认(无参)构造函数”。 当我调用该方法时,它会进入错误块。
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());
解决方案对你无效? - MorficDateTimeDeserializer
没有无参构造函数,这确实是你的问题所在。如果你想只使用注解,你可以简单地扩展它并添加一个调用必要参数的无参构造函数。 - Morfic