I have the setup below below:
public class ValidationUtils {
public static class ValidationResults {
public List<ValidationError> validationErrors;
public boolean valid;
public ValidationResults(){
validationErrors = new ArrayList<>();
valid = true;
}
@Override
public String toString() {
return "ValidationResults [validationErrors=" + validationErrors
+ ", valid=" + valid + "]";
}
}
// some static methods that create instances of ValidationResults.
}
Upon serialization of ValidationResults class I get this error:
<pre><code>com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class play.data.validation.ValidationError and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: utils.ValidationResults["validationErrors"]->java.util.ArrayList[0])
I use play.libs.Json utility class which is just a wraper around Jackson's Object Mapper.
Does anyone know what the problem is and how I can solve this?
The structure of ValidationError class is as follows:
package play.data.validation;
import java.util.*;
import com.google.common.collect.ImmutableList;
/**
* A form validation error.
*/
public class ValidationError {
private String key;
private String message;
private List<Object> arguments;
/**
* Constructs a new <code>ValidationError</code>.
*
* @param key the error key
* @param message the error message
*/
public ValidationError(String key, String message) {
this(key, message, ImmutableList.of());
}
/**
* Constructs a new <code>ValidationError</code>.
*
* @param key the error key
* @param message the error message
* @param arguments the error message arguments
*/
public ValidationError(String key, String message, List<Object> arguments) {
this.key = key;
this.message = message;
this.arguments = arguments;
}
/**
* Returns the error key.
*/
public String key() {
return key;
}
/**
* Returns the error message.
*/
public String message() {
return message;
}
/**
* Returns the error arguments.
*/
public List<Object> arguments() {
return arguments;
}
public String toString() {
return "ValidationError(" + key + "," + message + "," + arguments + ")";
}
}