You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "John Wagenleitner (JIRA)" <ji...@apache.org> on 2016/10/25 16:39:58 UTC
[jira] [Commented] (GROOVY-7780) JSONBuilder/JSONSlurper: Option
to Only Include NonNull values
[ https://issues.apache.org/jira/browse/GROOVY-7780?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15605799#comment-15605799 ]
John Wagenleitner commented on GROOVY-7780:
-------------------------------------------
This will be possible in 2.5 with the new {{JsonGenerator}}. It doesn't cover the case for {{JsonSlurper}} (mentioned in the summary). Since the original pointer for this was a Stackoverflow question about {{JsonBuilder}}, I wonder if this can be resolved and a separate ticket opened for the {{JsonSlurper}} is that is something desired/needed?
{code}
import groovy.json.*
def content = [foo:'bar', baz:null]
def generator = new JsonGenerator.Options()
.excludeNulls()
.build()
assert generator.toJson(content) == '{"foo":"bar"}'
assert new JsonBuilder(content, generator).toString() == '{"foo":"bar"}'
{code}
> JSONBuilder/JSONSlurper: Option to Only Include NonNull values
> ---------------------------------------------------------------
>
> Key: GROOVY-7780
> URL: https://issues.apache.org/jira/browse/GROOVY-7780
> Project: Groovy
> Issue Type: Improvement
> Components: JSON
> Reporter: Pascal Schumacher
>
> requested on the mailing list, by Gerald Wiltse:
> {quote}I just found this article which describes the problem perfectly and there are several good workarounds.
> http://stackoverflow.com/questions/14749817/exclude-null-values-using-jsonbuilder-in-groovy
> Apparently, it's a native feature of Jackson, which makes me think it's probably available in lots of JSON API's.
> Any chance this feature could get on the roadmap for JSON Builder (and slurper for that matter)?{quote}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)