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:

@Path("ping")
public class PingResource {

    @GET
    @Path("{ping}")
    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.


Web Apps, SPA, PWA with vanilla Java Script (ES 6+), CSS 3 and WebStandards only. As simple as possible, but not simpler. See you at: (Progressive) Web apps, Single Page Apps and WebStandards airhacks workshops at MUC airport, Winter Edition

airhacks.fm the podcast:

Stay in touch: airhacks.news.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License