Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-6103

Nillable field, in a json payload, was sent as "@nil":"true" instead of an empty string

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.7.13
    • 3.0.3, 2.7.14, 3.1
    • JAX-RS
    • None
    • Windows Seven, Linux Red Hat Enterprise 6

    • Unknown

    Description

      Moving from CXF version 2.2.7 to 2.7.13 a nillable field, in a jax-rs client with json format, wil be sent with the annotation "@nil":"true" instead of an empty string (as configured).

      The request with the version 2.7.13

      ---------------------------
      ID: 1
      Address: http://localhost:8080/test/test/echo
      Http-Method: POST
      Content-Type: application/json
      Headers: {Accept=[application/json], Content-Type=[application/json]}
      Payload: {"nillableField":{"@nil":"true"}}
      --------------------------------------
      

      The request with the version 2.7.7

      ---------------------------
      ID: 1
      Address: http://localhost:8080/test/test/echo
      Http-Method: POST
      Content-Type: application/json
      Headers: {Accept=[application/json], Content-Type=[application/json]}
      Payload: {"nillableField":""}
      --------------------------------------
      

      The client configuration

      <bean id="simpleConverter" class="org.codehaus.jettison.mapped.SimpleConverter" />
      <bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
          <property name="dropRootElement" value="true" />
          <property name="ignoreNamespaces" value="true" />
          <property name="typeConverter" ref="simpleConverter" />
          <property name="supportUnwrapped" value="true" />
          <property name="writeXsiType" value="false" />
          <property name="serializeAsArray" value="true" />
          <property name="dropCollectionWrapperElement" value="false" />
          <property name="convention" value="mapped" />
      </bean>
      
      <jaxrs:client id="testServiceClient" address="http://localhost:8080/test/"     serviceClass="it.icteam.test.cxf.service.TestService">
          <jaxrs:headers>
              <entry key="Accept" value="application/json" />
          </jaxrs:headers>
          <jaxrs:providers>
              <ref bean="jsonProvider" />
          </jaxrs:providers>
          <jaxrs:features>
              <core:logging />
          </jaxrs:features>
      </jaxrs:client>
      

      The request Pojo

      package it.icteam.test.cxf.model;
      
      import javax.xml.bind.annotation.XmlAccessType;
      import javax.xml.bind.annotation.XmlAccessorType;
      import javax.xml.bind.annotation.XmlElement;
      import javax.xml.bind.annotation.XmlRootElement;
      
      /**
       * @author m.milesi
       */
      @XmlRootElement
      @XmlAccessorType(XmlAccessType.FIELD)
      public class TestRequest {
      
      	@XmlElement(required = true)
      	private String mandatoryField;
      	
      	@XmlElement(required = false)
      	private String optionalField;
      	
      	@XmlElement(required = true, nillable=true)
      	private String nillableField;
      
      	/**
      	 * @return the mandatoryField
      	 */
      	public String getMandatoryField() {
      		return mandatoryField;
      	}
      
      	/**
      	 * @param mandatoryField the mandatoryField to set
      	 */
      	public void setMandatoryField(String mandatoryField) {
      		this.mandatoryField = mandatoryField;
      	}
      
      	/**
      	 * @return the optionalField
      	 */
      	public String getOptionalField() {
      		return optionalField;
      	}
      
      	/**
      	 * @param optionalField the optionalField to set
      	 */
      	public void setOptionalField(String optionalField) {
      		this.optionalField = optionalField;
      	}
      
      	/**
      	 * @return the nillableField
      	 */
      	public String getNillableField() {
      		return nillableField;
      	}
      
      	/**
      	 * @param nillableField the nillableField to set
      	 */
      	public void setNillableField(String nillableField) {
      		this.nillableField = nillableField;
      	}
      }
      

      The service interface

      package it.icteam.test.cxf.service;
      
      import javax.ws.rs.Consumes;
      import javax.ws.rs.POST;
      import javax.ws.rs.Path;
      import javax.ws.rs.Produces;
      
      import it.icteam.test.cxf.model.TestRequest;
      import it.icteam.test.cxf.model.TestResponse;
      
      @Path("/test")
      @Consumes({ "application/json" })
      @Produces({ "application/json" })
      public interface TestService {
      	@Path("echo")
      	@POST
      	TestResponse echo(TestRequest request);
      }
      

      The maven dependencies

      <properties>
          <!-- cxf.version>2.7.7</cxf.version-->
          <cxf.version>2.7.13</cxf.version>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          <maven.compiler.source>1.7</maven.compiler.source>
          <maven.compiler.target>1.7</maven.compiler.target>
      </properties>
      <dependencies>
          <dependency>
              <groupId>org.apache.cxf</groupId>
      	<artifactId>cxf-bundle</artifactId>
      	<version>${cxf.version}</version>
          </dependency>
          <dependency>
              <groupId>org.apache.cxf</groupId>
              <artifactId>cxf-rt-rs-extension-providers</artifactId>
              <version>${cxf.version}</version>
          </dependency>
          <dependency>
              <groupId>org.codehaus.jettison</groupId>
              <artifactId>jettison</artifactId>
              <version>1.3.6</version>
          </dependency>
       </dependencies>
      

      Attachments

        1. cxf-6103-test-case.tar.gz
          2 kB
          Michele Milesi

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            mmilesi_icteam Michele Milesi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: