Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Won't Fix
-
Affects Version/s: 1.9.2
-
Fix Version/s: None
-
Component/s: Serializer
-
Labels:None
-
Number of attachments :
Description
public static interface Feed { public String getTitle(); public String getCategory(); } public static class MyFeed implements Feed { public String getTitle() { return "my title"; } public String getCategory() { return "my category"; } public String getAdditionalProperty() { return "my new prop"; } } public static class ProxyFeed implements Feed { @JsonUnwrapped @JsonSerialize or @JsonProperty private final Feed feed; public ProxyFeed(Feed feed) { this.feed = feed; } public String getTitle() { return "Proxy "+ feed.getTitle(); } public String getCategory() { return "Proxy " + feed.getCategory(); } public String getProxyProperty() { return "Proxy new prop"; } }
System.out.println(new ObjectMapper().writeValueAsString(new ProxyFeed(new MyFeed())));
Output:
{
"category":"my category",
"category":"Proxy my category",
"title":"my title",
"title":"Proxy my title",
"additionalProperty":"my new prop",
"proxyProperty":"Proxy new prop"
}
Output without @JsonSerialize or @JsonProperty for 'feed' in ProxyFeed ("additionalProperty" is missing):
{
"category":"Proxy my category",
"title":"Proxy my title",
"proxyProperty":"Proxy new prop"
}
I Want:
{
"category":"Proxy my category",
"title":"Proxy my title",
"additionalProperty":"my new prop",
"proxyProperty":"Proxy new prop"
}
What are you trying to do here? I don't quite understand the intent.
I don't think this is a bug – you have two set of properties, one from POJO, trying to add further unwrapped properties. This causes a conflict; and perhaps serializer could try to detect it.