json - play.data.Form understanding subclassing in Java play framework -


i use play.data.form feature of play!framework having problem following classes. could tell me if there way make forms aware of nested paths such inheritance structures? far have tried making work json. here digest of code.

@jsoninclude(jsoninclude.include.non_empty) public class contactparam implements ientityparam<contact> {      private long id;      private string name;      private list<contactfieldparam> contacts;      private long companyid;      //standard getters , setters } 

with details being defined follow:

@jsonsubtypes({         @type(emailfieldparam.class),         @type(phonefieldparam.class),         @type(socialnetworkfieldparam.class),         @type(addressfieldparam.class),         @type(websiteurlfieldparam.class) }) @jsontypeinfo(use = jsontypeinfo.id.name, include = jsontypeinfo.as.property, property = "ctype") @jsoninclude(jsoninclude.include.non_empty) public abstract class contactfieldparam implements ientityparam<contactfield> {      private long id;      //standard getters , setters } 

and of course subclasses implemented (with quite different set of fields) , have public default constructor available. have tested structure json (jackson on own , wrapped json implementation in play framework) , works. problem when try use in controller declaring form<contactparam>

private static final form<contactparam> contactform = form.form(contactparam.class);  public static result myaction() {      form<contactparam> form = contactform.bindfromrequest();      if(form.haserrors){      //...      }else{      //...      } } 

the binding give me error caused instanciationexception trying directly instance abstract class using newinstance() method of class<contactfieldparam>. determined studying springframework code used form class (databinder , beanwrapperimpl).

org.springframework.beans.invalidpropertyexception: invalid property 'contacts[0]' of bean class [crud.params.contact.contactparam]: illegal attempt property 'contacts' threw exception; nested exception org.springframework.beans.nullvalueinnestedpathexception: invalid property 'contacts' of bean class [crud.params.contact.contactparam]: not instantiate property type [crud.params.contact.fields.contactfieldparam] auto-grow nested property path: java.lang.instantiationexception [...] caused by: org.springframework.beans.nullvalueinnestedpathexception: invalid property 'contacts' of bean class [crud.params.contact.contactparam]: not instantiate property type [crud.params.contact.fields.contactfieldparam] auto-grow nested property path: java.lang.instantiationexception     @ org.springframework.beans.beanwrapperimpl.newvalue(beanwrapperimpl.java:633) 


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -