I have a java program which should serialize objects using jackson (play framework). It was working, but I messed it up somehow and now I can't get it working. Here is my serializer
public String serializeObject(Object object) {
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = null;
try {
json = ow.writeValueAsString(object);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return json;
}
and here is the code which runs it:
return badRequest(serializeObject(new Error("bad input")));
and the error class:
public class Error {
private String error;
public Error(String error) {
this.error = error;
}
}
and as the output, all I get is { }
What is wrong?
Your Error Class
's properties need to have setter and getters which you want to show in JSON
output
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With