Receiving JSON in the request body and turning that into java is possible, but not as easy as it should be. Specially when compared to other more modern languages (such as Ruby on Rails), java lacks some flexibilities which are sought for when manipulating schemaless external input.
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!
19. 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
25. THE PROBLEM: “JSON” TO “JAVA"
THE REST MODEL nested validation
Validation can be performed equally in child objects
26. THE PROBLEM: “JSON” TO “JAVA"
THE REST MODEL easy cast to many types and lists
27. THE PROBLEM: “JSON” TO “JAVA"
THE REST MODEL easy cast to many types and lists
Loads can be done with it.
28. 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
29. 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
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
MAY SOON BE RENAMED TO AIQUDO
31. TIME FOR Q&A
// HUDSON MENDES
github.com/hudsonmendes
twitter.com/hudsonmendes
medium.com/@hudsonmendes
linkedin.com/in/hudsonmendes