java - How to send nested json object to server using spring mvc + jackson -


i have hotel entity , has object called location.

@entity public class hotel implements serializable {       private static final long serialversionuid = 1l;       @id       @generatedvalue(strategy = generationtype.auto)       private long id;       string name;       @onetoone(fetch=fetchtype.lazy)       @joincolumn(name="loc_id")       location location;       //getter setter   } 

location object that:

@entity public class location implements serializable {      private static final long serialversionuid = 1l;      @id     @generatedvalue(strategy = generationtype.auto)     @column(name="loc_id")     private long id;      string name;      public location() {     }      public location(string name) {         this.name = name;     }      public string getname()     {         return name;     }     public void setname(string name)     {         this.name = name;     } } 

i can send location object server ({"name":"mynewloc"}). can send hotel object server name it's ok ({"name":"newhotel"}).

but when try send hotel object name , location attribute ({"name":"new hotel","location":{"name":"mynewloc"}}), 400 post error , response;

exception:"org.springframework.http.converter.httpmessagenotreadableexception"  message:"could not read json: template must not null or empty! (through reference chain: org.maskapsiz.sosyalkovan.domain.hotel["location"]); nested exception com.fasterxml.jackson.databind.jsonmappingexception: template must not null or empty! (through reference chain: org.maskapsiz.sosyalkovan.domain.hotel["location"])" 

i using jackson-mapper-asl 1.9.13 , spring boot.

i added @restresource(exported = false) , works me.

@entity @restresource(exported = false) public class location implements serializable { } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -