2 Replies Latest reply on Apr 9, 2010 8:33 PM by bgroeneveld

    Enable null or empty fields in JSON RESTEasy output

    bgroeneveld

      We are using RESTEasy to develop RESTful services with Seam 2.2.0.  We would like to have null or empty values show in JSON objects for both Jettison and Jackson providers.  For example, the spec says we should see:




      {
           "firstName": "John",
           "lastName": "Smith",
      }
      




      When the Java object is more like:




      {
           "firstName": "John",
           "middleInitial": null,
           "lastName": "Smith",
      }
      




      Without the middleInitial field being present our GWT client cannot do a getMiddleInitial() reliably.  We understand that there are ways to configure Jettison and Jackson to do the latter or similar, but we do not see how to configure this in RESTeasy with Seam. Can you help us?  Thanks!

        • 1. Re: Enable null or empty fields in JSON RESTEasy output
          gaborj

          Hi,


          I think this is not seam topic, not even RESTEasy but the providers you mention, probably try there with more success...
          In Jackson you can do:


          objectMapper.configure(SerializationConfig.WRITE_NULL_PROPERTIES, true);



          PS: Are you sure you want to send those bytes to the client without any useful information? What about the green aspects of programming? ;) Probably the client should handle that...

          • 2. Re: Enable null or empty fields in JSON RESTEasy output
            bgroeneveld

            Agreed, handling this on the client works well also.  Looks like Jackson also offers @JsonWriteNullProperties.  I might suggest everything Seam integrates is a candidate Seam topic in that the whole point of Seam is bringing all these technologies together.  Our challenge is in using Jackson in entity graph traversal.  Since Hibernate uses dynamic proxies to lazy load these need to be removed if you want to serve them up using JAX-RS and JAX-B.  So we end up pulling in the Gilead toolkit to  get hibernate out of our pojos and using the CycleRecoverable interface in Jettison to deal with natural loops in our entity graphs.  It works quite well; We just wish we could use Jackson, but it doesn't yet have enough configurable flexibility to deal cycles yet - as far as we have found.