0
votes

I followed the gwt 2.4 validation sample and implemented the whole stuff into my own App. The client side works great.

    private void verifyRegistrationData(final RegistrationTO registration) throws ConstraintViolationException {
        final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
        final Set<ConstraintViolation<RegistrationTO>> violations = validator.validate(registration);

        if (violations.size() > 0) {
            final Set<ConstraintViolation<?>> temp = new HashSet<ConstraintViolation<?>>(violations);
            throw new ConstraintViolationException(temp);
        ...

but if I do the same on the server side:

    public void update(final RegistrationTO registration) throws IllegalArgumentException, ConstraintViolationException, TestException {
    final Set<ConstraintViolation<RegistrationTO>> violations = validator.validate(registration);
    if (!violations.isEmpty()) {
        final Set<ConstraintViolation<?>> temp = new HashSet<ConstraintViolation<?>>(violations);
        throw new ConstraintViolationException(temp);
    }
    ...

the whole thing crashes with the following exception:
javax.servlet.ServletContext log: Exception while dispatching incoming RPC call com.google.gwt.user.client.rpc.SerializationException: Type 'org.hibernate.validator.engine.PathImpl' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.

That's how PathImpl looks like hibernate-validator-4.1.0.Final-sources.jar

public class PathImpl implements Path, Serializable {
    private static final long serialVersionUID = 7564511574909882392L;
    ...

looks OK (at least to me)

I am using GWT 2.4, validation-api-1.0.0.GA, hibernate-validator-4.1.0.Final, gwt-servlet-deps ...

Thanks in advance!

3
Welcome to the uncertain world of GWT-RPC. Switch to RequestFactory when it's still time, it's an advice. - Thomas Broyer

3 Answers

2
votes

Is there an explicitly defined a default constructor? i.e., public PathImpl() { } ? This is required by GWT's serialization mechanism; if it isn't in the source, serializing an RPC response will fail.

1
votes

A custom serializer does exist for PathImpl, it's just that unless that class is explicitly referenced in your service API, it's not going to be added to the serialization policy.

The current work around is to add a dummy PathImpl field somewhere in your service API. The ValidationSupport class exists to group this and other such classes together to make this a bit easier.

0
votes

I change the whole thing to RequestFactory as Thomas Broyer recommended. It was by far not so easy as GWT-RPC. This was the reason for me to collect all kind of informations and to build a sample program.

For those who are interested - here you can find a sample with documentation and source. (Single line client logger is also implemented) (Documentation is in German but logging-output aso. is in English...)