java - RequestBody + JSON -


i have problem convert json java class.

controller

@requestmapping(value = "/{username}/add", method = post)     public void add(@requestbody notemodel note) {         system.out.println(note.gettitle());     } 

json

{     title : "title",     text : "text" } 

notemodel

public class notemodel {     private string title;     private string text;      public string gettitle() {         return title;     }      public void settitle(string title) {         this.title = title;     }      public string gettext() {         return text;     }      public void settext(string text) {         this.text = text;     } } 

so, when send json controller, controller see same url, can't deserialize json java (i think). because, when try, send json - { title : "title" }, , controller wait argument - @requestbody string note, can display it.

i'm try do, in https://gerrydevstory.com/2013/08/14/posting-json-to-spring-mvc-controller/ , include adapter in servlet.xml, same effect.

ajax

$.ajax({         type : "post",         contenttype : "application/json; charset=utf-8",         url : window.location.pathname,         data : json.stringify({             title : $("#titleid").val(),             text : $("#textid").val()         }),         success: function () {             $("#titleid").val("");             $("#textid").val("");         }     }) 

make sure have added content-type "application/json" in header of request.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -