JSON-P: Removing a slot from a JsonObject with JsonPatch

With JsonPatch, you can remove a node, or perform multiple operations on an JsonObject instance:


import javax.json.Json;
import static javax.json.Json.createObjectBuilder;
import javax.json.JsonObject;
import javax.json.JsonPatch;


@Test
public void removeNode() {

    JsonObject project = createObjectBuilder().
            add("project", "thinwars").
            add("dev", createObjectBuilder().
                    add("name", "duke").
                    add("age", 18)).
            build();
    JsonPatch patch = Json.createPatchBuilder().
            remove("/dev").
            build();
    JsonObject projectWithoutDeveloper = patch.apply(project);

    assertFalse(projectWithoutDeveloper.containsKey("dev"));
    System.out.println(projectWithoutDeveloper);
}

The output is: {"project":"thinwars"}

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.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

2mins: Building a Custom Element (Web Component) which talks to Java EE 8 Microservice

Building a Custom Element (WebComponent) from scratch and connecting it with a Java EE backend in 2 minutes:

See you at Web Apps without frameworks starter and "Build to last" effectively progressive applications with webstandards only -- the "no frameworks, no migrations" approach, at Munich Airport, Terminal 2 or effectiveweb.training (online).


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Productive Clouds 2.0 with Serverless Jakarta EE--airhacks.fm podcast

Subscribe to airhacks.fm podcast via: RSS iTunes

An airhacks.fm conversation with Ondrej Mihályi about:

starting programming with Logo, Pascal, C, Pentium 386, Scratch, minecraft, delphi and Java, pointers and destructors, participating in programming competitions, learning programming with Java, GWT, JSF and Primefaces over GWT, Eclipse, NetBeans, Java EE 5 introduced Dependency Injection (DI), Nitra is the oldest City in Slovakia, "Enterprise needs to be complicated", code generation with xdoclet in J2EE, simplifications with Java EE 5 in 2006, starting at Payara, running a JUG in Prague, Sun Grid Engine, serverless WARs, ideas for productive Clouds 2.0, serverless Java EE applications, early clouds with Google App Engine, Docker and Kubernetes for application packaging, making cloud services injectable, AWS lambdas are distributed commands, improving developer experience in the clouds with DI instead of singletons, Payara Source To Image (S2I) for server configuration in the clouds, separating the immutable servers from application logic with docker and clouds, cloud vendors are evaluating microprofile, repeatable and reproducible builds with Java EE in private clouds, Java EE deployment model became accidentally "cloud ready", with ThinWARs there is nothing to (security) scan, with ThinWARs there is no conceptual difference to lambda functions, cloud vendors participation in Jakarta EE, GraalVM and native compilation. Ondro's blog and @OndroMih / twitter.

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.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

J2EE, Java EE, Jakarta EE, MicroProfile - and The Release Cadence

J2EE was released every 2 years, Java EE every 3-4 years:

  1. J2EE 1.2 (December 12, 1999)
  2. J2EE 1.3 (September 24, 2001) (2 years)
  3. J2EE 1.4 (November 11, 2003) (2 years)
  4. Java EE 5 (May 11, 2006) (3 years)
  5. Java EE 6 (December 10, 2009) (3 years)
  6. Java EE 7 (May 28, 2013) (4 years)
  7. Java EE 8 (August 31, 2017) (4 years)
[from: https://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition#cite_note-4]

With a Jakarta EE release in 2019 (status), the release cadence would come back to 2-years cycle of J2EE days. A Jakarta EE release in 2020 would be still aligned with the Java EE cadence. However: Jakarta EE plans to have more frequent releases.

All major application servers are already supporting both: Java EE 8 and MicroProfile at the same time (see matrix).

MicroProfile and most application servers are already released quarterly. Now you can write your ThinWAR applications against the stable Java EE 8 API and enjoy new MicroProfile features several times a year.

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.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

"Jakarta EE" Eclipse GlassFish 5.1 Docker Image is Available from Docklands and from Dockerhub

Eclipse GlassFish 5.1 docker image is available as Dockerfile from Docklands (glassfish) and docker image directly from dockerhub: airhacks/glassfish.

All projects created with the Java EE 8 Essential Archetype ship with a Dockerfile already pointing to airhacks/glassfish.

To create a project run:

mvn archetype:generate -DarchetypeGroupId=com.airhacks -DarchetypeArtifactId=javaee8-essentials-archetype -DarchetypeVersion=0.0.2 -DgroupId=com.airhacks -Dversion=0.0.1 -Darchetype.interactive=false --batch-mode -DartifactId=eclipsefish

to build:


cd eclipsefish
mvn clean install && docker build -t airhacks/eclipsefish .    
    

to run:

docker run -d -p 8484:8080 --name thinfish airhacks/thinfish

...and do smoke test:

curl http://localhost:8484/thinfish/resources/ping output:

HTTP/1.1 200 OK
Server: GlassFish Server Open Source Edition  5.1.0 
X-Powered-By: Servlet/3.1 JSP/2.3 (GlassFish Server Open Source Edition  5.1.0  Java/Oracle Corporation/1.8)
Content-Type: text/plain
Content-Length: 16

Enjoy Java EE 8!%          

Checkout wad.sh for continuous deployments.

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.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

KISS your WARs--Skipping the Superfluous

Both apache maven and Java EE heavily rely on (Convention over Configuration). Productive, straight-forward "Don't make me think" ThinWARs, fast builds and deployments, short pom.xml are a result of applying the built-in, sensible defaults.

Your WAR is KISS, if the maven artifactId and:
  1. project folder
  2. name in pom.xml (name is derived from artifactId, so remove it)
  3. WAR name
  4. finalName
  5. and so the JAX-RS URI
are identical.

Also

  1. there are no nice-to-have runtime dependencies
  2. there are no maven plugins declared
  3. there is no pom inheritance
  4. the only provided dependencies are the Java EE / Jakarta EE and MicroProfile API
Example:

<project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.airhacks</groupId>
   <artifactId>thinwar</artifactId>
   <version>0.0.1</version>
   <packaging>war</packaging>
   <dependencies>
       <dependency>
           <groupId>javax</groupId>
           <artifactId>javaee-api</artifactId>
           <version>8.0</version>
           <scope>provided</scope>
       </dependency>
       <dependency>
           <groupId>org.eclipse.microprofile</groupId>
           <artifactId>microprofile</artifactId>
           <version>1.3</version>
           <type>pom</type>
           <scope>provided</scope>
       </dependency>        
   </dependencies>
   <build>
       <finalName>thinwar</finalName>
   </build>
   <properties>
       <maven.compiler.source>1.8</maven.compiler.source>
       <maven.compiler.target>1.8</maven.compiler.target>
       <failOnMissingWebXml>false</failOnMissingWebXml>
   </properties>
</project> 

The resulting ThinWAR is KISS and YAGNI, without any Cargo Cult Programming involved.

A conventional ThinWAR project can be directly created with javaee8-essentials-archetype and deployed with wad.sh.

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.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

2min Tech Tip: Productivity with ThinWARs and Docker

In a few seconds you can build a Java EE + MicroProfile ThinWAR as a executable Docker container:

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.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

2019 predictions, Java EE authentication, JAX-RS and BeanValidation, perfect cases for Microservices, Docker vs. OpenShift--59th airhacks.tv

In the 59th airhacks.tv episode we discussed the following topics (https://gist.github.com/AdamBien/d65135a87731eb1da396cf853a5e2a2d)

"2019 predictions, Java EE authentication, JAX-RS and BeanValidation, perfect cases for Microservices, Docker vs. OpenShift, Java EE hosting, JPA and MicroServices, structuring SPAs, JSF vs. angular, JSF performance"

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.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Adding additional HTTP headers with JAX-RS and Bean Validation

A JAX-RS resource with input validation:


@Stateless
@Path("ping")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public class PingResource {

    @GET
    public String ping() {
        System.out.println(".");
        return "Enjoy Jakarta EE 8!";
    }

    @POST
    public void save(@Size(min = 2, max = 3) String ping) {
    }
}    

and installed ExceptionMapper

import java.util.stream.Collectors;
import javax.validation.ConstraintViolationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

@Provider
public class ContraintViolationMapper implements ExceptionMapper<ConstraintViolationException> {

    @Override
    public Response toResponse(ConstraintViolationException exception) {
        String messages = exception.getConstraintViolations().stream().
                map(v -> v.getMessage()).
                collect(Collectors.joining(","));
        return Response.status(400).header("reason", messages).build();
    }

}

...will return additional information in header on each contraint violation.

A failed input validation: curl -XPOST -i -H"Content-type: text/plain" -d'duke' http://localhost:8080/jaxrs-beanvalidation/resources/ping mainifests as:


HTTP/1.1 400 Bad Request
Server: Payara Server  5.184 #badassfish
reason: size must be between 2 and 3
(...)

The 7kB ThinWAR was built and deployed with wad.sh in 3 seconds.

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.


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Modern Frontends -- As Simple as Java EE (Istanbul JUG Session)

ThinWARs, no dependencies, a single specification source. Modern web applications based on web standards become as lean and productive: ...as modern Java EE with MicroProfile.

In this Istanbul JUG session "Modern Frontends -- As Simple as Java EE ", I'm building, deploying and connecting a "no dependencies", WebComponents / Custom Elements based fronted, with a ThinWAR microservice.

See you at "Build to last" effectively progressive applications with webstandards only -- the "no frameworks, no migrations" approach, at Munich Airport, Terminal 2 or effectiveweb.training (online).


NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Online Workshops
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License