Jackson JSON Processor
  1. Jackson JSON Processor
  2. JACKSON-835

@JsonUnwrapped duplicates property with @JsonSerialize or @JsonProperty

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.9.2
    • Fix Version/s: None
    • Component/s: Serializer
    • Labels:
      None
    • Number of attachments :
      0

      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"
      }

        Activity

        Tatu Saloranta made changes -
        Field Original Value New Value
        Status Open [ 1 ] In Progress [ 3 ]
        Tatu Saloranta made changes -
        Status In Progress [ 3 ] Closed [ 6 ]
        Resolution Won't Fix [ 2 ]

          People

          • Assignee:
            Tatu Saloranta
            Reporter:
            Jongsic Choi
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: