So you have a RESTful Java webapp built using Jersey, some POJO/JAXB models that you’d like to serialize using Jackson, and think it’d be sweet to validate models using annotations (JSR 303 – Bean Validation)? And you like your objects to be immutable (Effective Java Item #15). You’ve come to the right place. Hibernate Validator is the reference implementation for JSR 303 and arguably the best currently available, so we’ll use it along with Jersey and Jackson to form the backbone of this recipe.
The general idea behind the ValidatingJacksonJsonProvider
is that we can annotate any of the parameters used in our resource classes with @Valid
to have the object automatically validated during the Jackson JSON serialization process.
So, first, annotate your POJO/JAXB object with some constraints, like @Min(0)
and @NotEmpty
. Continued…
Book Review: Forging Truth
After a number of years away, my love of reading (non-textbooks) has returned. In the last two months, I’ve finished 6 or 7 books. Last one was probably five years before. Ok, maybe an exaggeration, but you get the picture.
One of the books that got me back into fiction was Forging Truth, by Raymond Masters. (disclaimers below)
Although I expected Forging Truth to be a typical fantasy/sci-fi piece, it ended up being a big mystery as well. It was this aspect that hooked me from the end of Chapter 2. The protagonist (and the reader) go through a journey of discovery, trying to recover his lost memories that are key to solving a crime against humanity. The book twisted and turned til the end, feeding you just enough information and back-story to keep you intrigued but not so much that the next pages were obvious.
Situated in present-day America, the novel was centered around subjects normally reserved for other (usually more medieval) contexts. This juxtaposition made for a very interesting read. Given this modern context, the language was easy and the approach to magic was “light” (i.e., unrestricted, not manna-based, etc.). However, the actual content/subject matter was a bit darker in nature, with some moderately graphic scenes. Action-packed til the end, this book left me hanging for more. Can’t wait to read the second book!
disclaimers: the links above are Amazon-affiliate links and the author is my uncle.
Posted in Commentary.
2 comments
By codyaray – April 18, 2012