In Boxfish (later acquired by AIQUDO) we had to deal with very flexible queryString inputs, requiring default values, that were optionals and that could not be easily or at all mapped to a POJO. In order to make it better, we developed the RestModel library. RestModel provides you with a map that gives you all of that in a beautiful fluent API.
8. THE PROBLEM: “JSON” TO “JAVA"
SOLUTION 1: SPRING (REST + JPA) 101
HOW HOMAKOV HACKED GITHUB AND THE LINE OF CODE THAT COULD HAVE PREVENTED IT
HTTPS://GIST.GITHUB.COM/PETERNIXEY/1978249
9. THE PROBLEM: “JSON” TO “JAVA"
SOLUTION 1: SPRING (REST + JPA) 101
WE NEED TO SANITISE THE DATA
BEFORE WE SAVE IT!
17. THE PROBLEM: “JSON” TO “JAVA"
THE REST MODEL
Good JSON-Serialisable error object
Chained instruction for setup
Cast-free conversions
18. RestModel
FEATURES
▸ All features from a
HashMap<String, Object>
▸ require, permit, permitAll
▸ json-friendly validation error object
▸ has, against “blank"
▸ rules
▸ type casting
▸ nested objects
20. THE PROBLEM: “JSON” TO “JAVA"
THE REST MODEL permit(key) + baseline(key)
Defaults “name" to "defaultName"
Uses whatever provided in the request body,
and uses the baseline if nothing was provided
26. THE PROBLEM: “JSON” TO “JAVA"
THE REST MODEL nested validation
Validation can be performed equally in child objects
27. THE PROBLEM: “JSON” TO “JAVA"
THE REST MODEL easy cast to many types and lists
28. THE PROBLEM: “JSON” TO “JAVA"
THE REST MODEL easy cast to many types and lists
Loads can be done with it.
29. RestModel
FEATURES & ADVANTAGES
▸ JSON keys normalisation (both
camelCase and snake_case
work)
▸ Simple linguistics to scrutinise
and validate input
▸ Also works with Lists and
Nested objects in the same way
▸ When validation errors are
found, provides good JSON
Serialisable Errors object
▸ It’s dependency free!
▸ Cast-free conversion of values
to (almost) all basic types.
▸ Fluent API for chained
instructions
▸ Used in production for 1 year,
1.4 released recently
30. RestModel
WANT TO HELP?
▸ It’s currently not possible to
extend the converters. We have it
to (almost all) basic types, but
registering your own ain’t possible
▸ Desired, but no way to
simply .bindTo(Entity.class) using
the require/permit rule
HTTPS://GITHUB.COM/BXFSH/BOXFISH-COMMONS-WEB-MODEL
31. RestModel
WANT TO HELP?
▸ It’s currently not possible to
extend the converters. We have it
to (almost all) basic types, but
registering your own ain’t possible
▸ Desired, but no way to
simply .bindTo(Entity.class) using
the require/permit rule
HTTPS://GITHUB.COM/BXFSH/BOXFISH-COMMONS-WEB-MODEL
MAY SOON BE RENAMED TO AIQUDO
32. TIME FOR Q&A
// HUDSON MENDES
github.com/hudsonmendes
twitter.com/hudsonmendes
medium.com/@hudsonmendes
linkedin.com/in/hudsonmendes