Generating JSON strings from Java objects with JSON-B
In addition to populating Java objects from JSON data, JSON-B can also generate JSON strings from Java objects. The following example illustrates how to do this:
package net.ensode.javaee8book.jsonbjavatojson.service; //imports omitted for brevity @Path("/customersearchcontroller") public class CustomerSearchControllerService { private final List<Customer> customerList = new ArrayList<>(); @GET @Path("{firstName}") public Response getCustomerByFirstName(@PathParam("firstName") String firstName) { List<Customer> filteredCustomerList; String jsonString; initializeCustomerList(); //method declaration omitted Jsonb jsonb = JsonbBuilder.create(); filteredCustomerList = customerList.stream().filter( customer -> customer.getFirstName().equals(firstName)). collect(Collectors.toList...