Jackson ObjectMapper 101

Jackson is a JSON processing library for Java. The code below will create an object mapper outputting JSON in pretty format and have case insensitive fields.

ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);

Jackson Wiki containing additional features:

Downloading file using Jersey

Very often, your application requires having a resource that allows users to download a file. This could be an endpoint where a user downloads some Report, their user data, or any other type of file.
To achieve this goal, you use StreamingOutput to copy the content of the file, and then add the stream to your Response object.

public Response download()
	String filename = "//someFolder/some-File.pdf"
	File file = new File(filename);
	final String newFileName = file.getName();
	StreamingOutput fileStream = output ->
			java.nio.file.Path path = Paths.get(filename);
			byte[] data = Files.readAllBytes(path);
		catch (Exception e)
			throw new WebApplicationException("File Not Found !!");
	return Response
			.ok(fileStream, MediaType.APPLICATION_OCTET_STREAM)
			.header("content-disposition", "attachment; filename = " + newFileName)