java ee - Can't serialize (json) object because weld crates a proxy "Unrecognized field "handler" -


i have many dto classes project serialize json used rest endpoints. extend (direct or indirect) abstract class "linkable" holds id of objects , creates self link using injected "uriinfo". working need inject instances of dtos. works fine.

lately created 2 other dto have additional level in hierarchy. problem if try inject instances of classes proxy (created weld). proxies contain aditional fields can't serialize because unknown (no getters or setters): com.fasterxml.jackson.databind.exc.unrecognizedpropertyexception: unrecognized field "handler"

so question is: why proxy instantiated , not class itself. workaround: can mark thos additional fields ignored somehow (the proxy subclass)?

here code of part of hierarchy different working dtos (createdbyuserrepresentation extends linkable):

public abstract class voterepresentation<t extends createdbyuserrepresentation> extends createdbyuserrepresentation{      @notnull     private t voteof;      @min(-1) // down vote     @max(1) // vote     private int value;      @asserttrue     public boolean valueisnotzero() {         return value != 0;     }      public t getvoteof() {         return voteof;     }      public int getvalue() {         return value;     }      public void setvoteof(t voteof) {         this.voteof = voteof;     }      public void setvalue(int value) {         this.value = value;     }  } 

the actual class:

@xmlrootelement(name = "problemvote", namespace = "urn:problems:problemvote") public class problemvoterepresentation extends voterepresentation<problemrepresentation> {      @override     protected class<?> getresourceclass() {         return problemvoteresource.class;     } } 

there extension of "voterepresentation". both have same problem: via cdi can obtain "proxy" instances additional fields not serializable. enough clues why sometime proxy used. read scope. in case class injects dto "requestscoped".

i found cause of odd behavior: annotation @asserttrue. if remove weld no longer uses proxy , serialization works fine.

this limits usage of javax.validation lot , think behavior not intended?!

edit martin kouba gave explanation behavior implied bean validation spec 10.1.2.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -