JAX-RS: Parameter to Object Mapping

A class containing a constructor with a single String parameter:

public class Ping {

    public String content;

    public Ping(String content) {
        this.content = content;

can be used as parameter of JAX-RS resources without any additional configuration:

public class PingResource {

    public String ping(@PathParam("ping") Ping ping) {
        return "Enjoy Jakarta EE with MicroProfile: " + ping.content;
curl -i http://localhost:8080/[WAR_NAME]/resources/ping/now yields:

HTTP/1.1 200 OK
Server: Payara Server  5.191 #badassfish

Enjoy Jakarta EE with MicroProfile: now%    

Project created with javaee8-essentials-archetype, the 4kB ThinWAR was built and deployed with: wad.sh in 2.1s

See you at Web, MicroProfile and Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments