{"action":"closed","issue":{"url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/481","labels_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/481/labels{/name}","comments_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/481/comments","events_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/481/events","html_url":"https://github.com/FasterXML/jackson-databind/issues/481","id":35099208,"number":481,"title":"Serialization of type info skipped for dynamically typed property.","user":{"login":"UnquietCode","id":146995,"avatar_url":"https://avatars.githubusercontent.com/u/146995?v=3","gravatar_id":"","url":"https://api.github.com/users/UnquietCode","html_url":"https://github.com/UnquietCode","followers_url":"https://api.github.com/users/UnquietCode/followers","following_url":"https://api.github.com/users/UnquietCode/following{/other_user}","gists_url":"https://api.github.com/users/UnquietCode/gists{/gist_id}","starred_url":"https://api.github.com/users/UnquietCode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UnquietCode/subscriptions","organizations_url":"https://api.github.com/users/UnquietCode/orgs","repos_url":"https://api.github.com/users/UnquietCode/repos","events_url":"https://api.github.com/users/UnquietCode/events{/privacy}","received_events_url":"https://api.github.com/users/UnquietCode/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-06-05T21:21:41Z","updated_at":"2015-11-05T23:15:42Z","closed_at":"2015-11-05T23:15:42Z","body":"Greetings! I have encountered some behavior which I have not been able to fully understand. Given an object with static typing (`@JsonSerialize(as=...`), are included properties serialized dynamically or statically? The behavior for the nested properties seems to be dynamic, but for the type ID it only considers the static type. The following example will make this clear.\r\n\r\n```java\r\nimport com.fasterxml.jackson.annotation.JsonProperty;\r\nimport com.fasterxml.jackson.annotation.JsonTypeInfo;\r\nimport com.fasterxml.jackson.databind.ObjectMapper;\r\nimport com.fasterxml.jackson.databind.annotation.JsonSerialize;\r\n\r\npublic class SubTypeProp {\r\n\r\n\tpublic static void main(String[] args) throws Exception {\r\n\t\tOuter outer = new Outer();\r\n\t\touter.setOne(\"1\");\r\n\r\n\t\tInner inner = new Inner();\r\n\t\tinner.setTwo(\"2\");\r\n\t\touter.setInner(inner);\r\n\r\n\t\tObjectMapper mapper = new ObjectMapper();\r\n\t\tString s = mapper.writer().writeValueAsString(outer);\r\n\t\tSystem.out.println(s);\r\n\t}\r\n\r\n\t@JsonTypeInfo(use=JsonTypeInfo.Id.NAME)\r\n\tinterface OuterType {\r\n\t\t@JsonProperty String getOne();\r\n\t\t@JsonProperty InnerType getInner();\r\n\t}\r\n\r\n\t@JsonSerialize(as=OuterType.class)\r\n\tstatic class Outer implements OuterType {\r\n\t\tprivate String one;\r\n\t\tprivate Inner inner;\r\n\r\n\t\t@Override\r\n\t\tpublic String getOne() {\r\n\t\t\treturn one;\r\n\t\t}\r\n\r\n\t\tpublic void setOne(String one) {\r\n\t\t\tthis.one = one;\r\n\t\t}\r\n\r\n\t\t@Override\r\n\t\tpublic Inner getInner() {\r\n\t\t\treturn inner;\r\n\t\t}\r\n\r\n\t\tpublic void setInner(Inner inner) {\r\n\t\t\tthis.inner = inner;\r\n\t\t}\r\n\t}\r\n\r\n\t@JsonTypeInfo(use=JsonTypeInfo.Id.NAME)\r\n\tinterface InnerType {\r\n\t\t@JsonProperty String getTwo();\r\n\t}\r\n\r\n\t@JsonSerialize(as=InnerType.class)\r\n\tstatic class Inner implements InnerType {\r\n\t\tprivate String two;\r\n\r\n\t\t@Override\r\n\t\tpublic String getTwo() {\r\n\t\t\treturn two;\r\n\t\t}\r\n\r\n\t\tpublic void setTwo(String two) {\r\n\t\t\tthis.two = two;\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nThe above example works correctly, and outputs this:\r\n```json\r\n{\r\n  \"@type\" : \"SubTypeProp$Outer\",\r\n  \"one\" : \"1\",\r\n  \"inner\" : {\r\n    \"@type\" : \"SubTypeProp$Inner\",\r\n    \"two\" : \"2\"\r\n  }\r\n}\r\n```\r\n\r\nBut if the declaration of `OuterType` is changed slightly, then the inner type id is dropped.\r\n```java\r\n@JsonTypeInfo(use=JsonTypeInfo.Id.NAME)\r\ninterface OuterType {\r\n\t@JsonProperty String getOne();\r\n\t@JsonProperty Object getInner();\r\n}\r\n```\r\n\r\nNote that the type of `getInner()` is now set to `Object`. Here is the corresponding output:\r\n```json\r\n{\r\n  \"@type\" : \"SubTypeProp$Outer\",\r\n  \"one\" : \"1\",\r\n  \"inner\" : {\r\n    \"two\" : \"2\"\r\n  }\r\n}\r\n```\r\n\r\nSo the type info is dropped in this case, but the properties themselves are still dynamically discovered. Does this seem like expected or unexpected behavior? This is the latest 2.4.0 release. Thanks!"}}