Posts tagged REST (2)

How to prevent runtime type erasure using GenericEntity in Jakarta REST in Jakarta EE 10

Java generics is a great feature that allows you to have compile time checks for generics. However, due to historical reasons of backward compatibility, type information for generics is erased at runtime. A lot of the time this shouldn’t be of much concern. But there are a few cases where type information is needed at runtime for some kind of decision. 

One such situation is in Jakarta REST when the jakarta.ws.rs.core.Response object is used to return a generic collection of a specific type. For example the code below shows the creation and return of a Response object that has a list of HelloEntity as the return payload to the client. 

Returning Beautiful Validation Error Messages In Jakarta REST With Exception Mappers

All non-trivial enterprise applications have some sort of constraints on the data the application processes. These constraints could range from the simplest to the most complex custom built types. The default validation API on theJakarta EEPlatform, Jakarta Bean Validation has excellent out of the box support for constraining bean fields. Then with its @Valid annotation, you can trigger automatic validation of constrained objects in certain points of an application. 

What’s New in Jakarta REST 3.1 in Jakarta EE 10?

The Representational State Transfer or RESTful architecture is a stateless, HTTP based communication standard for modern applications. It was originally proposed by Dr. Roy Fielding in hisPhD thesis. It has, over the years, become the default, programming language-agnostic means of enabling machine-to-machine communication. An application written in the Django framework in Python can have REST resources that are consumed by another application written in Java with Jakarta EE. Similarly, a Jakarta EE application can create resources that can be consumed by a C# application.  

Did You Know? Asynchronous REST Requests and Responses with Java EE and MicroProfile

Java EE 8 fully supports asynchronous handling of REST requests and responses, on both client and server side. This is useful to optimize throughput of an application or even when adopting reactive principles. MicroProfile type-safe REST client API also supports this concept to allow you to call REST services asynchronously with a much more straightforward way with plain Java interfaces.

Payara Platform on Microsoft Azure: Accessing SQL Databases

Microsoft Azure provides fully managed Cloud SQL databases for use by your Azure hosted cloud services. Payara® Micro is built to be the best runtime for Cloud Native Java EE and MicroProfile applications. Here’s how to rapidly create a REST web service that retrieves data from an Azure SQL Database and returns it as JSON.