{"action":"created","issue":{"url":"https://api.github.com/repos/caelum/vraptor4/issues/930","labels_url":"https://api.github.com/repos/caelum/vraptor4/issues/930/labels{/name}","comments_url":"https://api.github.com/repos/caelum/vraptor4/issues/930/comments","events_url":"https://api.github.com/repos/caelum/vraptor4/issues/930/events","html_url":"https://github.com/caelum/vraptor4/issues/930","id":55777217,"number":930,"title":"Controller generico","user":{"login":"jeancrbecker","id":10744173,"avatar_url":"https://avatars.githubusercontent.com/u/10744173?v=3","gravatar_id":"","url":"https://api.github.com/users/jeancrbecker","html_url":"https://github.com/jeancrbecker","followers_url":"https://api.github.com/users/jeancrbecker/followers","following_url":"https://api.github.com/users/jeancrbecker/following{/other_user}","gists_url":"https://api.github.com/users/jeancrbecker/gists{/gist_id}","starred_url":"https://api.github.com/users/jeancrbecker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeancrbecker/subscriptions","organizations_url":"https://api.github.com/users/jeancrbecker/orgs","repos_url":"https://api.github.com/users/jeancrbecker/repos","events_url":"https://api.github.com/users/jeancrbecker/events{/privacy}","received_events_url":"https://api.github.com/users/jeancrbecker/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-01-28T16:17:03Z","updated_at":"2015-01-28T21:18:54Z","closed_at":null,"body":"Galera alguem conseguiu criar um controller generico usando VRaptor 4.1 ? Quando utilizo metodos que recebem objetos como parametro ele não faz o reflection corretamente e acaba me retornando uma instancia de gson, agora quando incluo o tipo especifico da classe funciona sem problemas, ele apenas não reconhece quando é um tipo generico, precisaria fazer um interceptor ou um observer mas não tenho ideia de como implementar.\r\n\r\nMinha controller generica:\r\n\r\n```\r\npublic abstract class GenericController<T> {\r\n\r\n    protected GenericService genericService;\r\n    protected Result result;\r\n    private Class<T> entityClass;\r\n\r\n    public GenericController() {\r\n    }\r\n\r\n    @Inject\r\n    public GenericController(Class<T> entityClass, Result result, GenericService genericService) {\r\n        this.result = result;\r\n        this.genericService = genericService;\r\n        this.entityClass = entityClass;\r\n    }\r\n\r\n    @Permission(permissoes = {\"usuario.logado\"})\r\n    @Get(\"\")\r\n    public void listar() {\r\n        result.use(json()).withoutRoot().from(genericService.list()).serialize();\r\n    }\r\n\r\n    @Permission(permissoes = {\"usuario.logado\"})\r\n    @Get(\"{id}\")\r\n    public void getByID(Long id) {\r\n        result.use(json()).withoutRoot().from(genericService.find(id)).serialize();\r\n    }\r\n/**ESSE METODO NÃO FUNCIONA**/\r\n    @Permission(permissoes = {\"usuario.logado\"})\r\n    @Post(\"\")\r\n    @Consumes(value = \"application/json\", options = WithoutRoot.class)\r\n    public void novo(T entity) {\r\n        genericService.insert(entity);\r\n        result.use(json()).withoutRoot().from(\"ok\").serialize();\r\n    }\r\n/**ESSE METODO FUNCIONA**/\r\n    @Permission(permissoes = {\"usuario.logado\"})\r\n    @Put(\"\")\r\n    @Consumes(value = \"application/json\", options = WithoutRoot.class)\r\n    public void salvar(Menu entity) {\r\n        genericService.update(entity);\r\n        result.use(json()).withoutRoot().from(\"ok\").serialize();\r\n    }\r\n}\r\n\r\n```\r\n\r\nMinha controller especializada\r\n\r\n```\r\n@Controller\r\n@Path(\"/menus\")\r\npublic class MenuController extends GenericController<Menu> {\r\n\r\n    private MenuService menuService;\r\n\r\n    @Inject\r\n    public MenuController(Result result, MenuService menuService) {\r\n        super(Menu.class, result, menuService);\r\n    }\r\n\r\n    @Deprecated\r\n    public MenuController() {\r\n\r\n    }\r\n\r\n}\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/caelum/vraptor4/issues/comments/71918130","html_url":"https://github.com/caelum/vraptor4/issues/930#issuecomment-71918130","issue_url":"https://api.github.com/repos/caelum/vraptor4/issues/930","id":71918130,"user":{"login":"lucascs","id":46113,"avatar_url":"https://avatars.githubusercontent.com/u/46113?v=3","gravatar_id":"","url":"https://api.github.com/users/lucascs","html_url":"https://github.com/lucascs","followers_url":"https://api.github.com/users/lucascs/followers","following_url":"https://api.github.com/users/lucascs/following{/other_user}","gists_url":"https://api.github.com/users/lucascs/gists{/gist_id}","starred_url":"https://api.github.com/users/lucascs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucascs/subscriptions","organizations_url":"https://api.github.com/users/lucascs/orgs","repos_url":"https://api.github.com/users/lucascs/repos","events_url":"https://api.github.com/users/lucascs/events{/privacy}","received_events_url":"https://api.github.com/users/lucascs/received_events","type":"User","site_admin":false},"created_at":"2015-01-28T21:18:54Z","updated_at":"2015-01-28T21:18:54Z","body":"Não precisa chegar a tanto, só mudar aquele método que eu tinha linkado lá em cima já era o suficiente.\r\n\r\nPrecisa corrigir ele pra retornar o tipo certo no seu caso. Por isso eu falei pra vc escrever um teste e mandar um Pull request pra corrigir isso no VRaptor =)"}}