I have a web application. The front-end is in ember.js and the back-end is in Java, Spring MVC. I am facing a very weird problem.
I make an ajax request to my back-end and fetch some data. I return a custom object.
When I fetch data from the back-end on my local machine, all is fine but on a local server the custom object excludes Boolean
fields. (Rest fields like String are received fine).
In the class of my custom object, I have set the @JsonProperty
annotations on the getters and setters of these Boolean
variables.
In my javascript file, I am sending some params in an ajax request via GET
with contentType: "application/json"
This the controller:
@ResponseBody
@RequestMapping(value = "/getData", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public MyCustomObject(@RequestParam(value = "name") String name) {
MyCustomObject obj = null;
if(name != null) {
obj = fetchDataByName(name);
// obj.getInList() = false and obj.getIsParent() = false
// Values were properly initialized
}
return null;
}
I am 100% sure that the code is the same both on server and my local environment, and the data has those boolean variables before sending out the custom object.
I can't figure out what might be wrong here, am I missing some configuration? Or is there something else?
UPDATED:
public class MyCustomObject {
private ID id;
private Name name;
private InList inList;
private IsParent isParent;
@JsonProperty
public ID getID() { return this.id;}
@JsonProperty
public void setID(ID id) { this.id = id;}
@JsonProperty
public Name getName() { return this.name;}
@JsonProperty
public void setName(Name name) { this.name = name;}
@JsonProperty
public InList getInList() { return this.inList;}
@JsonProperty
public void setInList(InList inList) { this.inList = inList;}
@JsonProperty
public IsParent getIsParent() { return this.isParent;}
@JsonProperty
public void setIsParent(IsParent isParent) { this.isParent = isParent;}
}
public class ID {
String data;
@JsonProperty
public String getData() { return this.data;}
@JsonProperty
public void setData(String data) { this.data = data;}
}
public class Name {
String data;
@JsonProperty
public String getData() { return this.data;}
@JsonProperty
public void setData(String data) { this.data = data;}
}
public class InList {
Boolean data;
@JsonProperty
public Boolean getData() { return this.data;}
@JsonProperty
public void setData(Boolean data) { this.data = data;}
}
public class IsParent {
Boolean data;
@JsonProperty
public Boolean getData() { return this.data;}
@JsonProperty
public void setData(Boolean data) { this.data = data;}
}
But what I receieve from a GET
request through browser or in my app via an ajax
call:
{"ID":{"data":"123"},"Name":{"data":"MyName"},"InList":{},"IsParent":{}}