Java Magazine, Mar/Apr 2018
ORACLE COM JAVAMAGAZINE MARCH APRIL 2018 84 reactive programming RouterFunction routes BookRepository br return route GET books req ok body br findAll Book class andRoute GET books author req ok body br findByAuthor req pathVariable author Book class The functional reactive style lets you express HTTP endpoints as request predicates mapped to a handler class The handler class implementation is easily expressed as concise Java lambdas You can use the default request predicates or provide your own to gain full control over how requests are matched and dispatched In Listing 2 I produce a result and pass it to the body Publisher T method along with a class literal I need the class literal to help the engine figure out what type of message framing it should do Remember that Publisher T might produce billions of records it might never stop The producer cant aford to wait until all records have been produced and only then marshal the record from an object to JSON So it marshals each record as soon as it gets it I need to tell it what kind of message to look for In Spring MVC style controllers the return value a Publisher T in the handler methods encodes its generic parameter T and the engine can retrieve that generic parameter using reflection The engine cannot do the same thing for the instance variable passed into the body method as a parameter because there is no easy way to retrieve the generic signature The Spring Security framework supports a rich set of integrations with all manner of identity providers of instance variables This limitation is called type erasure The type literal gets you past this restriction If youre using the Kotlin language things are even more concise thanks to a
You must have JavaScript enabled to view digital editions.