admin管理员组文章数量:1122846
I have a class JobRequest
public class JobRequest {
private String type;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = AJobDetails.class, name = "A"),
@JsonSubTypes.Type(value = BJobDetails.class, name = "B")
})
private JobDetails job;
}
The issue is the key 'job' might not be present or null in the recieved JSON. When the model is initialised it throws an error.
MismatchedInputException: Missing property 'job' for external type id 'type'
Tried JsonInclude, defaultImpl=Void.class, and Optional.
In case of Optional, error is gone, but populated values are also populated as null.
本文标签: How to allow nullable fields along with JsonTypeInfo in Spring Boot and JacksonStack Overflow
版权声明:本文标题:How to allow nullable fields along with JsonTypeInfo in Spring Boot and Jackson - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736281227a1926247.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论