{"action":"opened","issue":{"url":"https://api.github.com/repos/DozerMapper/dozer/issues/691","repository_url":"https://api.github.com/repos/DozerMapper/dozer","labels_url":"https://api.github.com/repos/DozerMapper/dozer/issues/691/labels{/name}","comments_url":"https://api.github.com/repos/DozerMapper/dozer/issues/691/comments","events_url":"https://api.github.com/repos/DozerMapper/dozer/issues/691/events","html_url":"https://github.com/DozerMapper/dozer/issues/691","id":346155519,"node_id":"MDU6SXNzdWUzNDYxNTU1MTk=","number":691,"title":"CustomConverter - nested object of same type cannot be cast to itself??","user":{"login":"MacGyver27","id":6546231,"node_id":"MDQ6VXNlcjY1NDYyMzE=","avatar_url":"https://avatars0.githubusercontent.com/u/6546231?v=4","gravatar_id":"","url":"https://api.github.com/users/MacGyver27","html_url":"https://github.com/MacGyver27","followers_url":"https://api.github.com/users/MacGyver27/followers","following_url":"https://api.github.com/users/MacGyver27/following{/other_user}","gists_url":"https://api.github.com/users/MacGyver27/gists{/gist_id}","starred_url":"https://api.github.com/users/MacGyver27/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MacGyver27/subscriptions","organizations_url":"https://api.github.com/users/MacGyver27/orgs","repos_url":"https://api.github.com/users/MacGyver27/repos","events_url":"https://api.github.com/users/MacGyver27/events{/privacy}","received_events_url":"https://api.github.com/users/MacGyver27/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-31T11:57:15Z","updated_at":"2018-07-31T11:57:15Z","closed_at":null,"author_association":"NONE","body":"Hello,\r\n\r\nI am facing a blocker type of problem with Dozer custom converter. At the moment I am not able to solve it via docker mapper but doing it manually works - no extra logic and it works outside docker custom converter.\r\n\r\n* Dozer version: 6.2.0\r\n* OS version: Ubuntu 18.04\r\n* JDK version: 1.8.0_171\r\n\r\nClasses - **Source side** representation:\r\n```java\r\npublic abstract class NetworkObjectDTOAbstract {\r\n\r\n    @JsonProperty(\"id\")\r\n    private Long id;\r\n\r\n    @JsonProperty(\"name\")\r\n    private String name;\r\n\r\n    @JsonProperty(\"class_name\")\r\n    private String className;\r\n\r\n    @JsonProperty(\"ip\")\r\n    private String ip;\r\n\r\n    @JsonProperty(\"netmask\")\r\n    private String netmask;\r\n\t\r\n}\r\n\r\npublic class NetworkObjectDTO1 extends NetworkObjectDTOAbstract {\r\n\r\n    @JsonProperty(\"member\")\r\n    private MemberDTO member;\r\n}\r\n\r\npublic class NetworkObjectDTO2 extends NetworkObjectDTOAbstract {\r\n\r\n    @JsonProperty(\"member\")\r\n    private List<MemberDTO> member;\r\n}\r\n```\r\nClasses - **Destination side** representation:\r\n```java\r\npublic class NetworkObjectDTO {\r\n\r\n    @JsonProperty(\"id\")\r\n    private Long id;\r\n\r\n    @JsonProperty(\"name\")\r\n    private String name;\r\n\r\n    @JsonProperty(\"class_name\")\r\n    private String className;\r\n\r\n    @JsonProperty(\"ip\")\r\n    private String ip;\r\n\r\n    @JsonProperty(\"netmask\")\r\n    private String netmask;\r\n\r\n    @JsonProperty(\"member\")\r\n    private List<MemberDTO> member;\r\n}\r\n```\r\nDozer **CustomConverter**:\r\n```java\r\npublic class MemberToListSimpleConverter implements CustomConverter {\r\n\r\n    @Override\r\n    public Object convert(Object dst, Object src, Class<?> dstClass, Class<?> srcClass) {\r\n        if (src instanceof MemberDTO) {\r\n            List<MemberDTO> list = new ArrayList();\r\n            list.add((MemberDTO) src);\r\n            return list;\r\n        }\r\n        if (src instanceof List) {\r\n            return ((List) src).get(0);\r\n        }\r\n        return null;\r\n    }\r\n}\r\n```\r\n\r\n**Mapping** definition:\r\n```xml\r\n    <!--Network Object-->\r\n    <!--<mapping>-->\r\n        <!--<class-a>com.att.portalapp.nextgendc.module.arcs.dto.network_object.tufin.NetworkObjectDTOAbstract</class-a>-->\r\n        <!--<class-b>com.att.portalapp.nextgendc.module.arcs.dto.network_object.NetworkObjectDTO</class-b>-->\r\n    <!--</mapping>-->\r\n    <mapping>\r\n        <class-a>com.att.portalapp.nextgendc.module.arcs.dto.network_object.tufin.NetworkObjectDTO1</class-a>\r\n        <class-b>com.att.portalapp.nextgendc.module.arcs.dto.network_object.NetworkObjectDTO</class-b>\r\n        <field custom-converter=\"com.att.portalapp.nextgendc.module.arcs.converter.MemberToListSimpleConverter\">\r\n            <a>member</a>\r\n            <b>member</b>\r\n        </field>\r\n    </mapping>\r\n    <mapping>\r\n        <class-a>com.att.portalapp.nextgendc.module.arcs.dto.network_object.tufin.NetworkObjectDTO2</class-a>\r\n        <class-b>com.att.portalapp.nextgendc.module.arcs.dto.network_object.NetworkObjectDTO</class-b>\r\n        <field>\r\n            <a>member</a>\r\n            <b>member</b>\r\n        </field>\r\n    </mapping>\r\n\r\n```\r\n\r\nSo from seeing the class definition you see I am trying to achieve pretty simple thing.. In case **MemberDTO** is object, make it a list of 1 value - that's it.\r\n\r\nHowever in **CustomConverter** it never enters if clause. I am not getting why? It is the same object at both places.. When I do a test before the if statement in **CustomConverter**: `src = (MemberDTO) src;` it fails on **cannot be cast**  error: `java.lang.ClassCastException: com.***.module.arcs.dto._custom.MemberDTO cannot be cast to com.***.module.arcs.dto._custom.MemberDTO`\r\n\r\nFrom the debug session:\r\n![image](https://user-images.githubusercontent.com/6546231/43458170-ffa55752-947d-11e8-8f19-28ac4adf1a10.png)\r\n![image](https://user-images.githubusercontent.com/6546231/43458191-16be9aca-947e-11e8-9685-9289a593280d.png)\r\n\r\nAm I missing something? Appreciate any response. Thanks, Michal"}}
{"actor":{"display_login":"MacGyver27"}}