#dataformat #endpoint #Jackson #jackson-dataformat-xml #JSON #REST #Spring #Spring Boot #T4SD #Tips 4 Spring Devs #XML

T4SD (Tips 4 Spring Devs): How to get Spring Boot REST endpoints to speak XML

Many of us use JSON almost exclusively now, which is generally a good thing. But what happens when you need to “speak XML” with your Spring Boot REST endpoints? XML support in Spring Boot’s REST endpoints is not enabled by default, but adding it isn’t difficult at all. Simply add the following dependency to your POM (or similar entry to your Gradle build file, if that’s the way you roll) and rebuild: ...

#content type #filtering #GetMapping #java #request header #request header filtering #RequestMapping #Spring #Spring Boot #T4SD #Tips 4 Spring Devs

T4SD (Tips 4 Spring Devs): Request header filtering in @RequestMapping

Just a quick tip for the Spring fans out there…​ I was leading a workshop yesterday and this question arose: Is it possible to filter requests by header content using Spring’s various request mapping (@RequestMapping, @GetMapping, @PostMapping, et al) annotations? Not only is it possible, it’s easy, and the implementation is concise & clean! Let’s take a look.  The code Here is a simple example that filters based upon the content-type of the header: ...

#query method #quick tip #REST #Spring #Spring Data #Spring Data REST #T4SD #Tips 4 Spring Devs

T4SD (Tips 4 Spring Devs): Exposing Query Methods in Spring Data REST

Spring Data REST takes an opinionated approach to exposing Spring Data repositories via REST endpoints, covering the 80-90% use case with a minimum of code and fuss. But did you know that it provides a no-lifting-required mechanism for exposing query methods you define on those repositories as well? Let’s say you create a method like this: Referencing that bit of functionality directly is simple, just append /search/<methodName> to the collection endpoint: ...