-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Describe the bug
When a POJO attribute contains an object of a class annotated with @JsonTypeInfo
, the method serializeWithType()
changes the current value, so that it references that inner object when processing it (such as MailAttachment
, in the example below). This behavior was introduced due to #631.
However, this current value also has a side-effect on subsequent sibling attributes. In the following sample, the JsonGenerator would state MailStatement as current value when processing "actions" and "properties". This behaviour breaks Jackson Property Filters, such as Squiggly (https://github.com/bohnman/squiggly/issues/62)
Note that if the Attachment class has no @JsonTypeInfo annotation, then "actions" and "properties" correctly state Issue object as current value.
{
"id": "ISSUE-1",
"issueSummary": "Dragons Need Fed",
"issueDetails": "I need my dragons fed pronto.",
"reporter": {
"firstName": "Daenerys",
"lastName": "Targaryen",
"entityType": "User"
},
"assignee": {
"firstName": "Jorah",
"lastName": "Mormont",
"entityType": "User"
},
"attachment": {
"@class": ".MailAttachment",
"id": "1234",
"name": "Mail",
"from": "from@mail.com",
"to": "to@mail.com"
},
"actions": [
{
"id": null,
"type": "COMMENT",
"text": "I'm going to let Daario get this one..",
"user": {
"firstName": "Jorah",
"lastName": "Mormont",
"entityType": "User"
}
},
{
"id": null,
"type": "CLOSE",
"text": "All set.",
"user": {
"firstName": "Daario",
"lastName": "Naharis",
"entityType": "User"
}
}
],
"properties": {
"email": "motherofdragons@got.com",
"priority": "1"
}
}
Attribute processing, together with their JsonStreamContext "currentValue":
== id: com.github.bohnman.squiggly.model.Issue@222114ba
== issueSummary: com.github.bohnman.squiggly.model.Issue@222114ba
== issueDetails: com.github.bohnman.squiggly.model.Issue@222114ba
== reporter: com.github.bohnman.squiggly.model.Issue@222114ba
== firstName: com.github.bohnman.squiggly.model.User@1283bb96
===== reporter: com.github.bohnman.squiggly.model.Issue@222114ba
== lastName: com.github.bohnman.squiggly.model.User@1283bb96
===== reporter: com.github.bohnman.squiggly.model.Issue@222114ba
== entityType: com.github.bohnman.squiggly.model.User@1283bb96
===== reporter: com.github.bohnman.squiggly.model.Issue@222114ba
== assignee: com.github.bohnman.squiggly.model.Issue@222114ba
== firstName: com.github.bohnman.squiggly.model.User@74f0ea28
===== assignee: com.github.bohnman.squiggly.model.Issue@222114ba
== lastName: com.github.bohnman.squiggly.model.User@74f0ea28
===== assignee: com.github.bohnman.squiggly.model.Issue@222114ba
== entityType: com.github.bohnman.squiggly.model.User@74f0ea28
===== assignee: com.github.bohnman.squiggly.model.Issue@222114ba
== attachment: com.github.bohnman.squiggly.model.Issue@222114ba
== id: com.github.bohnman.squiggly.model.MailAttachment@409bf450
===== attachment: com.github.bohnman.squiggly.model.MailAttachment@409bf450
== name: com.github.bohnman.squiggly.model.MailAttachment@409bf450
===== attachment: com.github.bohnman.squiggly.model.MailAttachment@409bf450
== from: com.github.bohnman.squiggly.model.MailAttachment@409bf450
===== attachment: com.github.bohnman.squiggly.model.MailAttachment@409bf450
== to: com.github.bohnman.squiggly.model.MailAttachment@409bf450
===== attachment: com.github.bohnman.squiggly.model.MailAttachment@409bf450
== actions: com.github.bohnman.squiggly.model.MailAttachment@409bf450
== properties: com.github.bohnman.squiggly.model.MailAttachment@409bf450
Version information
2.9 - 2.12.3