admin管理员组文章数量:1336645
It seems that fasterxml treats the property of the parent object incorrectly, when used with JsonTypeInfo.As.WRAPPER_OBJECT. We have the following hierarchy:
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.WRAPPER_OBJECT
)
@JsonSubTypes({
@JsonSubTypes.Type(value = FailedNotification.class, name = "FailedNotification"),
@JsonSubTypes.Type(value = StartedNotification.class, name = "StartedNotification")
})
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Notification {
@NotNull
private String code;
}
And subtypes:
@NoArgsConstructor
@AllArgsConstructor
@Data
@EqualsAndHashCode(callSuper = true)
@JsonRootName("FailedNotification")
public class FailedNotification extends Notification {
private String sourceId;
}
@NoArgsConstructor
@AllArgsConstructor
@Data
@EqualsAndHashCode(callSuper = true)
@JsonRootName("StartedNotification")
public class StartedNotification extends Notification {
private String sourceId;
}
But the deserialization
new XmlMapper().readValue("""
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StartedNotification>
<code>123</code>
<sourceId>source-is-here</sourceId>
</StartedNotification>
""", Notification.class);
fails with:
Exception in thread "main" com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'code' as a subtype of
Notification
: known type ids = [FailedNotification, Notification, StartedNotification]
本文标签:
版权声明:本文标题:java - Fasterxml Jackson polymorphic deserialization with WRAPPER_OBJECT: Could not resolve type id 'field' as a 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742408366a2469284.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论