Hi all, I'm having trouble figuring out the right way to approach this and I'm wondering if some of y'all know a better way than what I've got so far.
My problem is this: I have some API objects that are posted to an endpoint where some fields are value types (like UUIDs) that are de/serialized via JSON using their string representation. I would like to continue using these types in the API object, but I would also like to have the Hibernate validator report on when these are improperly formatted (along with all its other validation checks). The problem I'm having is that the validator runs on the fully deserialized object, so the endpoint will fail on improperly formatted UUIDs during the *deserialization* process. This results in a 400 response with no feedback from the validator about what's wrong with the JSON. The best solution I've come up with so far is this: * I create a builder for the API object that accepts strings instead of UUIDs * I mark up the builder with jackson annotations and validator annotations to specify the correct format of the string. The builder's `build()` method will create the full API object, converting the Strings to UUIDs * The resource method accepts the builder - jackson will deserialize the json to the builder, validations run on the builder, and the resource either receives a fully valid builder or rejects the input with a 422 and the list of failing validations. * The resource method calls the builder's `build()` method to get the API object, which it can then use to get its job done. (An example of what this looks like lives here: https://github.com/dguardado/validator-test) This feels slightly unsatisfying but I'm not sure I see another way around this. I would love it if the receiver wouldn't have to explicitly call `build` to get a valid, fully-formed object. Has anyone else tried to do something like this? If so, what was your approach to it? If this *is* the generally accepted pattern for doing this type of thing, would it be useful to have the framework support it? (If so, I'd be happy to submit a patch for it) Thanks! -Dimas -- You received this message because you are subscribed to the Google Groups "dropwizard-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.