Getting null as a property value Json spring auto conversion

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
Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
Just thinking out loud (I'm not in a position to test this at the moment), perhaps because you have a setter method, it is being used rather than field injection and so the annotation is being missed.

Try copying the @JsonProperty annotation to the setter and getter methods and see if that resolves the issue. Also, if the setter method is not needed by your code, you could try removing it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rohit BajajAuthor Commented:
Still the same issue modified the code to :
 @JsonProperty("html")
    public String getBody() {
        return body;
    }

    @JsonProperty("html")
    public void setBody(String body) {
        this.body = body;
    }

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.