Spring boot-Res中@RequestBody上的JsonDeserialization
有没有人能帮我理解一下,有什么东西会导致Spring boot-Res中@RequestBody上的JsonDeserialization,spring,spring-boot,Spring,Spring Boot,有没有人能帮我理解一下,有什么东西会导致@RequestBody上无法调用JsonDeserializer @RequestMappy(method=POST, value = /InfraSpec) ResponseEntity<InfraSpec> createInfrastructure(@AuthenticationPrincipal User user, @RequestBody InfraSpec infraSpec) { InfraSpec infs = inf
@RequestBody
上无法调用JsonDeserializer
@RequestMappy(method=POST, value = /InfraSpec)
ResponseEntity<InfraSpec> createInfrastructure(@AuthenticationPrincipal User user, @RequestBody InfraSpec infraSpec)
{
InfraSpec infs = infrRepository.saveAnFlush(infraSpec);
ResponseEntity<InfraSpec> resEntity = new ResponeEntity(infs, HttpStatus.Ok);
return resEntity ;
}
@Entity
@JsonDeserialiser(using= InfraSpecDeserializer)
public Class InfraSpec
{
//....
}
public class InfraSpecDeserializer extends JsonDeserializer<InfraSpec> {
@Override
public InfraSpec deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException
{
InfraSpec ifs = new InfraSpec();
// logic to parse the jsoneNode and populate ifs
return ifs;
}
}
@RequestMappy(方法=POST,值=/InfraSpec)
ResponseEntity createInfrastructure(@AuthenticationPrincipal User,@RequestBody InfraSpec InfraSpec)
{
InfraSpec infs=infrarepository.saveAnFlush(InfraSpec);
ResponseEntity Recentity=新的响应实体(infs,HttpStatus.Ok);
回报怨恨;
}
@实体
@JsonDeserialiser(使用=InfraSpecDeserializer)
公共类基础规范
{
//....
}
公共类InfraSpecDeserializer扩展JsonDeserializer{
@凌驾
公共InfraSpec反序列化(JsonParser jp,反序列化上下文ctxt)引发IOException,JsonProcessingException
{
InfraSpec ifs=新的InfraSpec();
//解析jsoneNode并填充ifs的逻辑
返回ifs;
}
}
我为格式错误和文章不完整而道歉
好消息是我发现了这个问题:问题出在我使用org.codehouse.jackson时
当我将代码更改为使用com.fasterxml.jackson.**时,JsonDeserializer被按预期调用。这篇文章不仅格式不好,而且您发布的代码显然已损坏。如果您不想后期生成代码,这是可以的。但请发些至少能让我道歉并感谢你抽出时间的东西。我会记住的