{"action":"created","issue":{"url":"https://api.github.com/repos/google/gson/issues/712","repository_url":"https://api.github.com/repos/google/gson","labels_url":"https://api.github.com/repos/google/gson/issues/712/labels{/name}","comments_url":"https://api.github.com/repos/google/gson/issues/712/comments","events_url":"https://api.github.com/repos/google/gson/issues/712/events","html_url":"https://github.com/google/gson/issues/712","id":111635877,"number":712,"title":"Serialization issue with RuntimeTypeAdapterFactory","user":{"login":"ultraon","id":6382537,"avatar_url":"https://avatars.githubusercontent.com/u/6382537?v=3","gravatar_id":"","url":"https://api.github.com/users/ultraon","html_url":"https://github.com/ultraon","followers_url":"https://api.github.com/users/ultraon/followers","following_url":"https://api.github.com/users/ultraon/following{/other_user}","gists_url":"https://api.github.com/users/ultraon/gists{/gist_id}","starred_url":"https://api.github.com/users/ultraon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ultraon/subscriptions","organizations_url":"https://api.github.com/users/ultraon/orgs","repos_url":"https://api.github.com/users/ultraon/repos","events_url":"https://api.github.com/users/ultraon/events{/privacy}","received_events_url":"https://api.github.com/users/ultraon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"swankjesse","id":133019,"avatar_url":"https://avatars.githubusercontent.com/u/133019?v=3","gravatar_id":"","url":"https://api.github.com/users/swankjesse","html_url":"https://github.com/swankjesse","followers_url":"https://api.github.com/users/swankjesse/followers","following_url":"https://api.github.com/users/swankjesse/following{/other_user}","gists_url":"https://api.github.com/users/swankjesse/gists{/gist_id}","starred_url":"https://api.github.com/users/swankjesse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/swankjesse/subscriptions","organizations_url":"https://api.github.com/users/swankjesse/orgs","repos_url":"https://api.github.com/users/swankjesse/repos","events_url":"https://api.github.com/users/swankjesse/events{/privacy}","received_events_url":"https://api.github.com/users/swankjesse/received_events","type":"User","site_admin":false},"milestone":null,"comments":5,"created_at":"2015-10-15T15:00:13Z","updated_at":"2016-02-23T07:59:43Z","closed_at":null,"body":"Hello, i found after serialization root object 'type' field is not injected, for inner object 'type' fields are added. Example:\r\n```\r\npublic class Test {\r\n  public class Base {\r\n    String baseField = \"base\";\r\n  }\r\n  public class Child extends Base {\r\n    String childField = \"child\";\r\n    Base baseInChild = new Base();\r\n  }\r\n\r\n  public static void main(String[] args) {\r\n        Gson mGson = new GsonBuilder()\r\n                .setPrettyPrinting()\r\n                .registerTypeAdapterFactory(\r\n                        RuntimeTypeAdapterFactory.\r\n                                of(Base.class).\r\n                                registerSubtype(Base.class).\r\n                                registerSubtype(Child.class)\r\n                )\r\n                .create();\r\n\r\n        final String jsonStr = mGson.toJson(new Child());\r\n        final Base child = mGson.fromJson(jsonStr, Base.class); // ERROR HERE: \"Caused by: com.google.gson.JsonParseException: cannot deserialize class mypackage.Test$Base because it does not define a field named type\"\r\n  }\r\n}\r\n```\r\nand json output after serialization:\r\n```\r\n{\r\n  \"baseInChild\": {\r\n    \"type\": \"Base\",\r\n    \"baseField\": \"base\"\r\n  },\r\n  \"childField\": \"child\",\r\n  \"baseField\": \"base\"\r\n//in this place should be generated field 'type' with value 'Child'\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/google/gson/issues/comments/187592151","html_url":"https://github.com/google/gson/issues/712#issuecomment-187592151","issue_url":"https://api.github.com/repos/google/gson/issues/712","id":187592151,"user":{"login":"nsarathk","id":1336094,"avatar_url":"https://avatars.githubusercontent.com/u/1336094?v=3","gravatar_id":"","url":"https://api.github.com/users/nsarathk","html_url":"https://github.com/nsarathk","followers_url":"https://api.github.com/users/nsarathk/followers","following_url":"https://api.github.com/users/nsarathk/following{/other_user}","gists_url":"https://api.github.com/users/nsarathk/gists{/gist_id}","starred_url":"https://api.github.com/users/nsarathk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nsarathk/subscriptions","organizations_url":"https://api.github.com/users/nsarathk/orgs","repos_url":"https://api.github.com/users/nsarathk/repos","events_url":"https://api.github.com/users/nsarathk/events{/privacy}","received_events_url":"https://api.github.com/users/nsarathk/received_events","type":"User","site_admin":false},"created_at":"2016-02-23T07:59:43Z","updated_at":"2016-02-23T07:59:43Z","body":"@swankjesse i guess thats where the problem is. i tried using the same it didnt work. Am about to try with the solution which @ultraon has given."}}