I am trying to deserialize an object send with postman using gson.fromJson.
@POST
@Path( "company" ) // takes name as a path parameter
@Produces( "application/json" ) // response formatted as JSON
public Response insertCompany(String content) {
Gson gson = new Gson();
CompanyWithNoIdReturn newCompany = gson.fromJson(content, CompanyWithNoIdReturn.class);
}
public class CompanyWithNoIdReturn {
private final String name;
private final String description;
private final String logo;
public CompanyWithNoIdReturn(String name, String description, String logo)
{
this.name = name;
this.description = description;
this.logo = logo;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getLogo() {
return logo;
}
}
The error that comes up is: javax.servlet.ServletException:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1
I understand that it means that it expects it to begin with {
and not "
as mentioned in here. Though what i have not understood is how do i fix it?
The json was contructed like this:
EDIT: While using form - data the content is like:
content = (java.lang.String) "------WebKitFormBoundaryUG5yy1gW9G2V5qcz
Content-Disposition: form-data; name="CompanyName"
newCompanyName2
------WebKitFormBoundaryUG5yy1gW9G2V5qcz
Content-Disposition: form-data; name="Description"
newDescription2
------WebKitFormBoundaryUG5yy1gW9G2V5qcz
Content-Disposition: form-data; name="logo"
newLogo2
------WebKitFormBoundaryUG5yy1gW9G2V5qcz--
"