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 05845200B7F for ; Sun, 11 Sep 2016 17:47:44 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 0453C160AC7; Sun, 11 Sep 2016 15:47:44 +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 EE369160AB6 for ; Sun, 11 Sep 2016 17:47:42 +0200 (CEST) Received: (qmail 90000 invoked by uid 500); 11 Sep 2016 15:47:42 -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 89989 invoked by uid 99); 11 Sep 2016 15:47:42 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Sep 2016 15:47:42 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id A47BE1812B4 for ; Sun, 11 Sep 2016 15:47:41 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.179 X-Spam-Level: * X-Spam-Status: No, score=1.179 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx2-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id BmphFCuOtUSY for ; Sun, 11 Sep 2016 15:47:37 +0000 (UTC) Received: from mail-wm0-f44.google.com (mail-wm0-f44.google.com [74.125.82.44]) by mx2-lw-eu.apache.org (ASF Mail Server at mx2-lw-eu.apache.org) with ESMTPS id 63A7F5F230 for ; Sun, 11 Sep 2016 15:47:37 +0000 (UTC) Received: by mail-wm0-f44.google.com with SMTP id c131so20725249wmh.0 for ; Sun, 11 Sep 2016 08:47:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=BmXvci9YjnXDMy3LMWu4Un4DrWw0o7UOoiTVanYI9+g=; b=Qy9NWOiPEW12ph6lC7Hfn/PT3CFhpDunfeJ6wn9DOnB8LQjNKRBijtxQM6bLRfpeMi QeQg0xAWQrhHURrQI3bKvh2+6Oj23vqBGk0qlNRNNdg+Dd5w/5SHRR/v9AnNGVaUjFEi uABUHrLRKOTUHYsd+gBmD2joa4GsuviriqcrYJiaA4z0z5gNY/D1oH3f+Ec0/A06lbqM yG+Yd8mHtt9++eUEfujCApRLm9m+y4HRWDOpuUFfKVeFEC/Yzby/UFBmeBNfPPedt6o3 3rEfYt7DeoLtU9GUWxmymUPjzKwYKKhTreTxFbMQ5yheyF7dhJkVLHzm4jKfR6WxsPXq gICw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=BmXvci9YjnXDMy3LMWu4Un4DrWw0o7UOoiTVanYI9+g=; b=YgEoAaS8mKEKZP2+RzF11fe5Q0qbTSpB9oaogSjgCH1ZlTtXuco6CMeLHiu71p8tqx HfqOfecERuW2xyG1lByq7jjIpHfllVhV9x+DRPmOhRN2nNCXuX4ZD+4bBRoy9vzuOr6N ZX1gyZqeOSYcw1LU3K36/EpKIRgKa2EOsIFVi/qTA6RVlNEwXOJVXrJyx/Lt7te8oaP7 mY5ZLlMqjDSeVyqg3wtybmNN99klqxzKZJ31gO5fZ0Mv5TT3sqhIS12RFYkXNvkyH1g3 TWLYCvPzul9O0Z/273ufnEUA2zJCdKiXq963ybiCIOumkeZetaIdoN2bPfsNXwU3Fq0i wLTw== X-Gm-Message-State: AE9vXwPjFhtSRhvjLhLhqAEPdwJ1IZeCKFS4e9Tw/2YzIK0UxN8nqcMmsMxG5FF8dHXvvamXYxVT59BoRL7b7A== X-Received: by 10.28.158.1 with SMTP id h1mr7308932wme.94.1473608856821; Sun, 11 Sep 2016 08:47:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.195.28.8 with HTTP; Sun, 11 Sep 2016 08:47:36 -0700 (PDT) In-Reply-To: <07E97BCC-F30A-4E50-BCDD-35455E928CAD@anc.org> References: <07E97BCC-F30A-4E50-BCDD-35455E928CAD@anc.org> From: Guillaume Laforge Date: Sun, 11 Sep 2016 17:47:36 +0200 Message-ID: Subject: Re: JsonOutput serialization options feature To: users@groovy.apache.org Content-Type: multipart/alternative; boundary=001a114b2f6a72f216053c3d4ca9 archived-at: Sun, 11 Sep 2016 15:47:44 -0000 --001a114b2f6a72f216053c3d4ca9 Content-Type: text/plain; charset=UTF-8 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+ --001a114b2f6a72f216053c3d4ca9 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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 chance to look at your pull request, but the lack of conf= igurability is the main reason I use Jackson instead of the Groovy JsonBuil= der/JsonOutput classes.

Keith

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

Groovy Json users,

I recent= ly worked on a project where it would have been helpful if JsonOutput/JsonB= uilder/StreamingJsonBuilder had options for controlling the output.=C2= =A0 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<= /a>).


GROOVY-6699: JSON slurper ability to ignore propertie/field names (at le= ast 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 JodaTim= e (for now via a closure converter)
GROOVY-7780: JSONBuilder/JSONSlurper: Option to Only I= nclude NonNull values
GROOVY-7858: Make JsonBuilder configurable to not write entries with= null values

[2] =C2=A0
import groovy.json.*

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

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

builder.records {
car {=
name 'H= SV Maloo'
make &#= 39;Holden'
year 2006
country 'Australia'
homepage new URL('http://example.org')
record {
= type 'spee= d'
= description 'production pickup truck with speed of 271kph'
}
}
}<= br>
assert wri= ter.toString() =3D=3D &= #39;{"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 committer= & PMC Vice-President
Developer Advocate @ Google= Cloud Platform

--001a114b2f6a72f216053c3d4ca9--