I am trying to send the custom object to the server side using Volley framework's Post method. i know the getBody method should be overloaded. But what to be specified as body content type? code of getBody() and getBodyContentType() methods will save my day.
This is my Model class:
package ar.sample.model;
import java.sql.Timestamp;
public class Location {
private Integer id;
private String locationName;
private Double latitude;
private Double longitude;
private Float radius;
private String logicalGroup;
private String parentLocation;
private String country;
private String city;
private String type;
private String description;
private Integer status;
private Timestamp createdTime;
private Timestamp updatedTime;
private String createdByUser;
private String updatedByUser;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getLocationName() {
return locationName;
}
public void setLocationName(String locationName) {
this.locationName = locationName;
}
public Double getLatitude() {
return latitude;
}
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
public Double getLongitude() {
return longitude;
}
public void setLongitude(Double longitude) {
this.longitude = longitude;
}
public Float getRadius() {
return radius;
}
public void setRadius(Float radius) {
this.radius = radius;
}
public String getLogicalGroup() {
return logicalGroup;
}
public void setLogicalGroup(String logicalGroup) {
this.logicalGroup = logicalGroup;
}
public String getParentLocation() {
return parentLocation;
}
public void setParentLocation(String parentLocation) {
this.parentLocation = parentLocation;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Timestamp getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Timestamp createdTime) {
this.createdTime = createdTime;
}
public Timestamp getUpdatedTime() {
return updatedTime;
}
public void setUpdatedTime(Timestamp updatedTime) {
this.updatedTime = updatedTime;
}
public String getCreatedByUser() {
return createdByUser;
}
public void setCreatedByUser(String createdByUser) {
this.createdByUser = createdByUser;
}
public String getUpdatedByUser() {
return updatedByUser;
}
public void setUpdatedByUser(String updatedByUser) {
this.updatedByUser = updatedByUser;
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("id", id)
.add("locationName", locationName)
.add("latitude", latitude)
.add("longitude", longitude)
.add("radius", radius)
.add("logicalGroup", logicalGroup)
.add("parentLocation", parentLocation)
.add("country", country)
.add("city", city)
.add("type", type)
.add("description", description)
.add("status", status)
.add("createdTime", createdTime)
.add("updatedTime", updatedTime)
.add("createdByUser", createdByUser)
.add("updatedByUser", updatedByUser)
.toString();
}
}
My code at server side is:
@RequestMapping(value = "/location", method = RequestMethod.POST)
public Location createLocationComplete(@RequestBody @Valid Location location) {
LOGGER.debug("API: Create {}", location);
//location = composeLocation(location);
return locationService.insert(location);
}
How to send the location object through POST method using Volley framework?