Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C5239200B7F for ; Sun, 11 Sep 2016 20:16:04 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C38BF160AC7; Sun, 11 Sep 2016 18:16:04 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BBC50160AB6 for ; Sun, 11 Sep 2016 20:16:03 +0200 (CEST) Received: (qmail 75407 invoked by uid 500); 11 Sep 2016 18:16:02 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 75397 invoked by uid 99); 11 Sep 2016 18:16:02 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Sep 2016 18:16:02 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 688DA1A0349 for ; Sun, 11 Sep 2016 18:16:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.198 X-Spam-Level: * X-Spam-Status: No, score=1.198 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id W_d_kdA1xwpt for ; Sun, 11 Sep 2016 18:15:57 +0000 (UTC) Received: from mail-oi0-f47.google.com (mail-oi0-f47.google.com [209.85.218.47]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 6D54E5FAD5 for ; Sun, 11 Sep 2016 18:15:56 +0000 (UTC) Received: by mail-oi0-f47.google.com with SMTP id m11so262666858oif.1 for ; Sun, 11 Sep 2016 11:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=NJco4DYkwQ0WH0k62r2knZ6+7li2VhoGw2oTRwYGTkg=; b=cMx2S9V6YkD2E04btQK7X61pm7M1Gdv4Fl8girk50z5fD8LOxlkDvrqw8YGXCYSKfE n5zHvK9LfzeXoIvqrD7JkPA1uoOx4flCeLEbVUMKy6V14TWNtZtOnuRpxlMWYRQHXAiW JB93kziIQkxay662PORq3L0QQjzszNHPZ/9e8ayceDRSruDVCtl780MJbJ7Yw4KwOh6k yOBgKw/8VDFR4e0JfD372om8c8MNZcH2T85FB5tT9LEMNYz5gsyPninTrMdyp1cxqcAe +xFnfuM51GMHYqv3umaRETH4+GL2s7lDqC5KGTWiyE9FSZ4EfiA0lVaRZUII336Kvmyo C6eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=NJco4DYkwQ0WH0k62r2knZ6+7li2VhoGw2oTRwYGTkg=; b=hOFAhR9V73C7kwuyKNrmZsbR+wiKLIlF5B279bQxzhET9KC0KKpvixAQpV9pKUvXYn XvwwpWSnkA8NS9WSbkAuIPj9/hv/Y+JDJS4kRY5Ga1rK8SJscxRQH1Abpww871txp2B7 jevlnW811RTQSTKhgP2xax+487VzDMobFKpHFB5IUvJUXbQ6ukgXlmR4/8gXAk7rvQtt CyM+TndPfNMGsPoXqmuNJzY3NLzXe0aJxy3HSuKNBzJhHJscHmvp0ht5MD6x1LjnZWIj Y/NwgCUTKNMmKZRu2USRBvCX9hCsOdZgI+1//trWE4Hd5C2DEaQc5Q3sKo3h+Pkjy7d5 g15A== X-Gm-Message-State: AE9vXwOLUtux7issdFOpZJwdnGioOueqJ3L1rFKdpVHGRRANubdHHzvORCRS0EzpagNgllQEP+jy7cuACxPR+A== X-Received: by 10.157.20.239 with SMTP id r44mr17201129otr.54.1473617755091; Sun, 11 Sep 2016 11:15:55 -0700 (PDT) MIME-Version: 1.0 References: <07E97BCC-F30A-4E50-BCDD-35455E928CAD@anc.org> In-Reply-To: From: Robert Stagner Date: Sun, 11 Sep 2016 18:15:44 +0000 Message-ID: Subject: Re: JsonOutput serialization options feature To: users@groovy.apache.org Content-Type: multipart/alternative; boundary=001a113d0f88d3bea2053c3f5ef1 archived-at: Sun, 11 Sep 2016 18:16:05 -0000 --001a113d0f88d3bea2053c3f5ef1 Content-Type: text/plain; charset=UTF-8 +1 from me. I like the ability to pick and choose what I can exclude On Sun, Sep 11, 2016 at 8:47 AM Guillaume Laforge wrote: > More options sounds like a good idea. > > On Sun, Sep 11, 2016 at 5:43 PM, Suderman Keith wrote: > >> +1 >> >> I haven't had a chance to look at your pull request, but the lack of >> configurability is the main reason I use Jackson instead of the Groovy >> JsonBuilder/JsonOutput classes. >> >> Keith >> >> On Sep 10, 2016, at 8:59 PM, John Wagenleitner < >> john.wagenleitner@gmail.com> wrote: >> >> Groovy Json users, >> >> I recently worked on a project where it would have been helpful if >> JsonOutput/JsonBuilder/StreamingJsonBuilder had options for controlling the >> output. I noticed there were some open tickets [1] for feature requests >> around this so decided to try to add some options to control the >> serialization and have proposed a pull request ( >> https://github.com/apache/groovy/pull/371). >> >> Just wanted to poll those that use the Json generating features in Groovy >> to see if you think these options would be useful and would welcome any >> code review for those that would be interested in reviewing the PR. For a >> quick overview I've included a sample below [2]. >> >> [1] >> GROOVY-6699: JSON slurper ability to ignore propertie/field names (at >> least the serializing part) >> GROOVY-6854: JsonOutput should be configurable with ISO 8601 UTC time >> zone instead of GMT >> GROOVY-7682: JsonBuilder or JsonOutput incompatible with JodaTime (for >> now via a closure converter) >> GROOVY-7780: JSONBuilder/JSONSlurper: Option to Only Include NonNull >> values >> GROOVY-7858: Make JsonBuilder configurable to not write entries with null >> values >> >> [2] >> >> import groovy.json.* >> >> def options = JsonOutput.options() >> .excludeNulls() >> .excludeFieldsByName('make', 'country', 'record') >> .excludeFieldsByType(Number) >> .addConverter(URL) { url -> '"http://groovy-lang.org"' } >> >> StringWriter writer = new StringWriter() >> StreamingJsonBuilder builder = new StreamingJsonBuilder(writer, options) >> >> builder.records { >> car { >> name 'HSV Maloo' >> make 'Holden' >> year 2006 >> country 'Australia' >> homepage new URL('http://example.org') >> record { >> type 'speed' >> description 'production pickup truck with speed of 271kph' >> } >> } >> } >> >> assert writer.toString() == '{"records":{"car":{"name":"HSV Maloo","homepage":"http://groovy-lang.org"}}}' >> >> >> ------------------------------ >> Research Associate >> Department of Computer Science >> Vassar College >> Poughkeepsie, NY >> >> >> >> ------------------------------ >> Research Associate >> Department of Computer Science >> Vassar College >> Poughkeepsie, NY >> >> > > > -- > Guillaume Laforge > Apache Groovy committer & PMC Vice-President > Developer Advocate @ Google Cloud Platform > > Blog: http://glaforge.appspot.com/ > Social: @glaforge / Google+ > > --001a113d0f88d3bea2053c3f5ef1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
+1 from me.=C2=A0 I like the ability to pick and choose wh= at I can exclude

O= n Sun, Sep 11, 2016 at 8:47 AM Guillaume Laforge <glaforge@gmail.com> wrote:
More options sounds like a good idea.
=

On Sun, Sep 11, 2016 at 5:43 PM, Suderman Keith <suderman= @anc.org> wrote:
+1

I haven't had a chanc= e to look at your pull request, but the lack of configurability is the main= reason I use Jackson instead of the Groovy JsonBuilder/JsonOutput classes.=

Keith

On Sep 10, 2016, at 8:59 PM, John Wagenleitner <john.wagenleitner= @gmail.com> wrote:

Groovy Json u= sers,

I recently worked on a project where it woul= d have been helpful if JsonOutput/JsonBuilder/StreamingJsonBuilder had opti= ons for controlling the output.=C2=A0 I noticed there were some open ticket= s [1] for feature requests around this so decided to try to add some option= s to control the serialization and have proposed a pull request (https://githu= b.com/apache/groovy/pull/371).

Just wanted to = poll those that use the Json generating features in Groovy to see if you th= ink these options would be useful and would welcome any code review for tho= se that would be interested in reviewing the PR.=C2=A0 For a quick overview= I've included a sample below [2].

[1]=C2=A0GROOVY-6699: JSON slurper ability to ignore= propertie/field names (at least the serializing part)
GROOVY-6854: JsonOutput should be c= onfigurable with ISO 8601 UTC time zone instead of GMT
GROOVY-7682: JsonBuilder or JsonOut= put incompatible with JodaTime (for now via a closure converter)
GROOVY-7780: JSONBuilder/= JSONSlurper: Option to Only Include NonNull values
GROOVY-7858: Make JsonBuilder configura= ble to not write entries with null values

[2] =C2= =A0
import gro=
ovy.json.*

def options =3D JsonOutput.options()
.excludeNulls()
= .excludeFieldsByName(&= #39;make', &= #39;country', 'record')
.excludeFieldsByType(Number)
= .addConverter(URL) { url -> '"http://groovy-lang.org"' }

StringWriter writer = =3D new StringWri= ter()
StreamingJsonBuilder builder =3D new StreamingJsonBuilder(writer, options)

b= uilder.records {
car {
name 'HSV Maloo'
make 'Holden'
year 2006
country 'Australia= '
= homepage new URL('http://example.org')=
record {
type 'speed'
description 'production pickup truck with speed of 271= kph'
= }
}
}

assert writer.toString() =3D=3D '{"records":{"car":{"= ;name":"HSV Maloo","homepage":"http://groovy-lang.org"}}}= '

------------------------------
Research Associate
Department of C= omputer Science
Vassar College
Poughkeepsie, NY



------------------------------
Research Associate
Department of C= omputer Science
Vassar College
Poughkeepsie, NY




--
Guillaume Laforge
Apache Groovy co= mmitter & PMC Vice-President
Developer Advocate @= Google Cloud Platform

--001a113d0f88d3bea2053c3f5ef1--