Coder Social home page Coder Social logo

jersey-1.x-null-value's Introduction

Jersey Null Value Issue

A test case for observing an empty value that gets marshaled as a null; first observed upon switching to JDK 1.8.0_161.

root@292c522d413f:/usr/local/tomcat# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

Getting Started

The following POM snippet shows the Jersey dependencies.

<properties>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<jersey.version>1.19.4</jersey.version>
</properties>

<dependencies>
	<dependency>
		<groupId>com.sun.jersey</groupId>
		<artifactId>jersey-bundle</artifactId>
		<version>${jersey.version}</version>
	</dependency>
	<dependency>
		<groupId>com.sun.jersey</groupId>
		<artifactId>jersey-server</artifactId>
		<version>${jersey.version}</version>
	</dependency>
</dependencies>

Our intention is to create an empty string value: "" with the expectation that is what we will receive.

@Path("/hello")
public class MyResource {
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	@Path("/jsonjaxb")
	public Response toJettisonJaxb() {
		XmlPojo pojo = new XmlPojo(1, "");
		return Response.ok().entity(pojo).build();		
	}
}

Instead, the empty value is marshaled to JSON as a null value.

Firefox

Docker

This project includes a docker image that can be used for testing. After starting up docker, browse to:

http://localhost:8080/jerseynullvalue-0.0.1/rest/hello/jsonjaxb

The structure of the docker image is as follows.

JDK8 >> Tomcat 8 >> Jersey 

The Jersey image is built upon the Tomcat image which is build upon the Oracle JDK8 image.

$ docker-compose up -d

If you need to change the underlying images, use the --build switch, e.g.

$ docker-compose up -d --build

jersey-1.x-null-value's People

Contributors

gkhays avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.