You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by nikosdim <ni...@gmail.com> on 2013/08/08 13:38:09 UTC
How to dynamically show and hide the null values of a response?
Hi
I have build a rest WS with CXF and what it does is fetching data from a
database and returns a list of POJO objects e.g. List<Book>
@XmlRootElement
public Book{
String title;
String author;
getters and setters...
}
Currently I have used the extentionMapping to get my result in json, jsonp
and xml. In order to get the .jsonp I have over-ridden the writeTo of the
org.apache.cxf.jaxrs.provider.json.JSONProvider
<jaxrs:extensionMappings>
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
<entry key="jsonp" value="application/javascript" />
</jaxrs:extensionMappings>
So lets say that in my List<Book> that I return in my with the
Response.status(Status.OK).entity(new GenericEntity<List<Book>>(books)
{}).build();
the author in some of the Book objects is null then in the response the
fields that was null will not be displayed. I know that if I set the
(nillable="true") in my Book then I will get the null fields in my response.
Is there any way to give to the user the option (with a query parameter
?returnNull=true) to set if he wants to get the null values back or not?
Thanks
--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-dynamically-show-and-hide-the-null-values-of-a-response-tp5732099.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: How to dynamically show and hide the null values of a response?
Posted by Sergey Beryozkin <sb...@gmail.com>.
I guess I misunderstood the question,
I see that you'd like nulls being reported without having to set a JAXB
nillable property, so no we can't do it. What is possible is to set a
nillable property but then configure JSONProvider to ignore xsi:nil &&
xsi:type attributes by setting its 'writeXsiType' property to false;
Cheers, Sergey
On 08/08/13 14:01, Sergey Beryozkin wrote:
> Hi
>
> I think we should enhance JSONProvider with a property like ignoreNull,
> false by default may be, if true - no null values will be reported
>
> Cheers, Sergey
> On 08/08/13 12:38, nikosdim wrote:
>> Hi
>>
>> I have build a rest WS with CXF and what it does is fetching data from a
>> database and returns a list of POJO objects e.g. List<Book>
>>
>> @XmlRootElement
>> public Book{
>> String title;
>> String author;
>>
>> getters and setters...
>> }
>>
>> Currently I have used the extentionMapping to get my result in json,
>> jsonp
>> and xml. In order to get the .jsonp I have over-ridden the writeTo of the
>> org.apache.cxf.jaxrs.provider.json.JSONProvider
>>
>> <jaxrs:extensionMappings>
>> <entry key="json" value="application/json" />
>> <entry key="xml" value="application/xml" />
>> <entry key="jsonp" value="application/javascript" />
>> </jaxrs:extensionMappings>
>>
>> So lets say that in my List<Book> that I return in my with the
>> Response.status(Status.OK).entity(new GenericEntity<List<Book>>(books)
>> {}).build();
>>
>> the author in some of the Book objects is null then in the response the
>> fields that was null will not be displayed. I know that if I set the
>> (nillable="true") in my Book then I will get the null fields in my
>> response.
>>
>> Is there any way to give to the user the option (with a query parameter
>> ?returnNull=true) to set if he wants to get the null values back or not?
>>
>> Thanks
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/How-to-dynamically-show-and-hide-the-null-values-of-a-response-tp5732099.html
>>
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: How to dynamically show and hide the null values of a response?
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
I think we should enhance JSONProvider with a property like ignoreNull,
false by default may be, if true - no null values will be reported
Cheers, Sergey
On 08/08/13 12:38, nikosdim wrote:
> Hi
>
> I have build a rest WS with CXF and what it does is fetching data from a
> database and returns a list of POJO objects e.g. List<Book>
>
> @XmlRootElement
> public Book{
> String title;
> String author;
>
> getters and setters...
> }
>
> Currently I have used the extentionMapping to get my result in json, jsonp
> and xml. In order to get the .jsonp I have over-ridden the writeTo of the
> org.apache.cxf.jaxrs.provider.json.JSONProvider
>
> <jaxrs:extensionMappings>
> <entry key="json" value="application/json" />
> <entry key="xml" value="application/xml" />
> <entry key="jsonp" value="application/javascript" />
> </jaxrs:extensionMappings>
>
> So lets say that in my List<Book> that I return in my with the
> Response.status(Status.OK).entity(new GenericEntity<List<Book>>(books)
> {}).build();
>
> the author in some of the Book objects is null then in the response the
> fields that was null will not be displayed. I know that if I set the
> (nillable="true") in my Book then I will get the null fields in my response.
>
> Is there any way to give to the user the option (with a query parameter
> ?returnNull=true) to set if he wants to get the null values back or not?
>
> Thanks
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-dynamically-show-and-hide-the-null-values-of-a-response-tp5732099.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>