{"action":"created","issue":{"url":"https://api.github.com/repos/nmorel/gwt-jackson/issues/45","labels_url":"https://api.github.com/repos/nmorel/gwt-jackson/issues/45/labels{/name}","comments_url":"https://api.github.com/repos/nmorel/gwt-jackson/issues/45/comments","events_url":"https://api.github.com/repos/nmorel/gwt-jackson/issues/45/events","html_url":"https://github.com/nmorel/gwt-jackson/issues/45","id":63702053,"number":45,"title":"Serializing some other object in custom serializer","user":{"login":"butlnor","id":11555256,"avatar_url":"https://avatars.githubusercontent.com/u/11555256?v=3","gravatar_id":"","url":"https://api.github.com/users/butlnor","html_url":"https://github.com/butlnor","followers_url":"https://api.github.com/users/butlnor/followers","following_url":"https://api.github.com/users/butlnor/following{/other_user}","gists_url":"https://api.github.com/users/butlnor/gists{/gist_id}","starred_url":"https://api.github.com/users/butlnor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/butlnor/subscriptions","organizations_url":"https://api.github.com/users/butlnor/orgs","repos_url":"https://api.github.com/users/butlnor/repos","events_url":"https://api.github.com/users/butlnor/events{/privacy}","received_events_url":"https://api.github.com/users/butlnor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-23T11:34:16Z","updated_at":"2015-03-23T13:30:12Z","closed_at":null,"body":"Hello!\r\n\r\nI don't find a way how to serialize some other object inside the \"doSerialize\" method of my custom serializer that extends JsonSerializer. \r\n\r\nLet's say I have classes A and B, and A contains field of type B. Now I have custom JSON serializers for both classes A and B and inside AJsonSerializer's doSerialize, I want to write the value of field B.\r\n\r\nThe thing is, I don't want to write B's fields inside the A's serializer, as in the real life the structure is much more complicated and a class like A contains many other objects. So serializer should be able to delegate each object's writing to its own serializer.\r\n\r\n\r\nExample:\r\n\r\npublic class AJsonSerializer extends JsonSerializer<A> {\r\n\t@Override\r\n\tprotected void doSerialize(JsonWriter writer, A value, JsonSerializationContext ctx, JsonSerializerParameters params) {\r\n\t\twriter.beginObject();\r\n\t\twriter.name(\"b\");\r\n\t\t// writer.value(value.getB()); <-- here I want to serialize B with its own custom serializer\r\n\t\twriter.endObject();\r\n\t}\r\n}\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nmorel/gwt-jackson/issues/comments/84997621","html_url":"https://github.com/nmorel/gwt-jackson/issues/45#issuecomment-84997621","issue_url":"https://api.github.com/repos/nmorel/gwt-jackson/issues/45","id":84997621,"user":{"login":"butlnor","id":11555256,"avatar_url":"https://avatars.githubusercontent.com/u/11555256?v=3","gravatar_id":"","url":"https://api.github.com/users/butlnor","html_url":"https://github.com/butlnor","followers_url":"https://api.github.com/users/butlnor/followers","following_url":"https://api.github.com/users/butlnor/following{/other_user}","gists_url":"https://api.github.com/users/butlnor/gists{/gist_id}","starred_url":"https://api.github.com/users/butlnor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/butlnor/subscriptions","organizations_url":"https://api.github.com/users/butlnor/orgs","repos_url":"https://api.github.com/users/butlnor/repos","events_url":"https://api.github.com/users/butlnor/events{/privacy}","received_events_url":"https://api.github.com/users/butlnor/received_events","type":"User","site_admin":false},"created_at":"2015-03-23T13:30:11Z","updated_at":"2015-03-23T13:30:11Z","body":"Wow thanks, that was what I was looking for. This works (except I had to use ObjectWriter<B> instead of JsonWriter<B>).\r\n\r\nThe reason for not using the annotations is, that the classes are in other older shared library projects, which must not have JSON annotations, as that projects are used elsewhere with custom build scripts, etc... So it's quite a requirement to leave the classes intact and not using additional dependencies.\r\n\r\nI am very grateful, thanks."}}