java - Serialize proxy object created by cglib -


as title, use jersey return object json, object created cglib proxy:

@get @produces(mediatype.application_json) @path("test") public response test() {     enhancer enhancer = new enhancer();     enhancer.setsuperclass(a.class);     enhancer.setcallback(new invocationhandler() {         public object invoke(object proxy, method method, object[] args) throws throwable {             return "my name";         }     });     return response.ok(enhancer.create()).build(); }  @data @xmlaccessortype(xmlaccesstype.property) public static class {     private string name; } 

it cannot work because enhancer.create() return proxy object of class a, not real object of class a.

org.codehaus.jackson.map.jsonmappingexception: no serializer found class myrest$1 , no properties discovered create beanserializer (to avoid exception, disable serializationconfig.feature.fail_on_empty_beans) ) (through reference chain: myrest$a$$enhancerbycglib$$fdcf8406["callbacks"])

the problem encounter cglib creates subclass of class not copy annotations. @ same time, annotations not inherited if not explicitly defined.

cglib not support annotations. overcome this, can choose use code generation library supports annotations. wrote such library, called byte buddy.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -