/** * Writes the JSON form of the Constraint Violation. * * @param constraintViolation the violation * @param jsonGenerator the generator * @param serializerProvider the provider * @throws IOException if it cannot be serialized */ @Override public void serialize(ConstraintViolationImpl constraintViolation, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("message", constraintViolation.getMessage()); Object invalidValue = constraintViolation.getInvalidValue(); if (invalidValue != null) { jsonGenerator.writeStringField("invalid", invalidValue.toString()); } if (constraintViolation.getPropertyPath() != null) { jsonGenerator.writeStringField("path", constraintViolation.getPropertyPath().toString()); } jsonGenerator.writeEndObject(); } }
/** * Only a subset of fields are actually serialized. * <p> * There is no guarantee that the root bean is GWT-serializable or that it's appropriate for it to * be exposed on the client. Even if the root bean could be sent back, the lack of reflection on * the client makes it troublesome to interpret the path as a sequence of property accesses. * </p> * The current implementation is the simplest-to-implement properties. * <ol> * <li>Message</li> * <li>Property Path</li> * </ol> * * @param streamWriter serialization stream writer * @param instance constraint violation * @throws SerializationException when serialization fails */ public static void serialize(final SerializationStreamWriter streamWriter, final ConstraintViolationImpl instance) throws SerializationException { // streamWriter.writeString(instance.getMessageTemplate()); streamWriter.writeString(instance.getMessage()); // streamWriter.writeObject(instance.getRootBeanClass()); // streamWriter.writeObject(instance.getRootBean()); // streamWriter.writeObject(instance.getLeafBean()); // streamWriter.writeObject(instance.getInvalidValue()); streamWriter.writeObject(instance.getPropertyPath()); // streamWriter.writeObject(instance.getConstraintDescriptor()); // ElementType }