We help IT Professionals succeed at work.
Get Started

Getting null as a property value Json spring auto conversion

Rohit Bajaj
Rohit Bajaj asked
on
175 Views
Last Modified: 2016-01-21
Hi,
From my js file there is an ajax call with the following data :
"{"title":"Title","html":"<div>Text</div><div><br></div>","message":"Message"}"

Open in new window

And i have a java class like :
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.springframework.web.util.HtmlUtils;

@JsonIgnoreProperties(ignoreUnknown = true)
public class Note {

    private String id;
    private String title;
    @JsonProperty("html")
    private String body;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public void parseHtml() {
        body = HtmlUtils.htmlEscape(body);
        title = HtmlUtils.htmlEscape(title);
    }

}

Open in new window

The controller corresponding to this request is :
   public void createNote(@RequestBody Note note, HttpServletResponse response) throws IOException {


Using debugger i found that although the value for title in note class is getting set properly but i am getting body = null.

what could be reason for that ?

Thanks
Comment
Watch Question
IT Business Systems Analyst / Software Developer
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE