From notifications-return-14828-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Wed Dec 12 07:33:46 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id D4BAB18064E for ; Wed, 12 Dec 2018 07:33:45 +0100 (CET) Received: (qmail 80479 invoked by uid 500); 12 Dec 2018 06:33:45 -0000 Mailing-List: contact notifications-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list notifications@groovy.apache.org Received: (qmail 80470 invoked by uid 99); 12 Dec 2018 06:33:44 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Dec 2018 06:33:44 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 89C63C04AB for ; Wed, 12 Dec 2018 06:33:44 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -108.501 X-Spam-Level: X-Spam-Status: No, score=-108.501 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, KAM_LIVE=1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 1v9duMAP7D9y for ; Wed, 12 Dec 2018 06:33:43 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 1A8A460CE0 for ; Wed, 12 Dec 2018 06:23:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 8E35EE0163 for ; Wed, 12 Dec 2018 06:23:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 214EC25302 for ; Wed, 12 Dec 2018 06:23:00 +0000 (UTC) Date: Wed, 12 Dec 2018 06:23:00 +0000 (UTC) From: "Paul King (JIRA)" To: notifications@groovy.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (GROOVY-8916) JsonOutput unable to serialize Locale object MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/GROOVY-8916?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D167= 18505#comment-16718505 ]=20 Paul King edited comment on GROOVY-8916 at 12/12/18 6:22 AM: ------------------------------------------------------------- One of the properties of the Locale class is the "default" Locale. Hence, t= hat object serializes into (your details may vary slightly): {code} {"loc":{"script":"","ISO3Country":"FRA","localeExtensions":null,"ISO3Langua= ge":"fra","displayCountry":"France", "default":{"script":"","ISO3Country":"AUS","localeExtensions":null,"ISO3= Language":"eng","displayCountry":"Australia", "default":{"script":"","ISO3Country":"AUS","localeExtensions":null,"IS= O3Language": ... {code} Rather than trying to handle cases like this, in Groovy 2.5 we added the ab= ility to customize JSON generation. You can look at the 2.5 release notes o= r view this blog here: http://mrhaki.blogspot.com/2018/06/groovy-goodness-customizing-json-output.= html In your case you can do: {code} import groovy.json.* def generator =3D new JsonGenerator.Options() .addConverter(Locale) { Locale loc -> loc.toString() } .build() println generator.toJson([loc: Locale.FRANCE]) // =3D> {"loc":"fr_FR"} {code} was (Author: paulk): One of the properties of the Locale class is the "default" Locale. Hence, t= hat object serializes into: {code} {"loc":{"script":"","ISO3Country":"FRA","localeExtensions":null,"ISO3Langua= ge":"fra","displayCountry":"France", "default":{"script":"","ISO3Country":"AUS","localeExtensions":null,"ISO3= Language":"eng","displayCountry":"Australia", "default":{"script":"","ISO3Country":"AUS","localeExtensions":null,"IS= O3Language": ... {code} Rather than trying to handle cases like this, in Groovy 2.5 we added the ab= ility to customize JSON generation. You can look at the 2.5 release notes o= r view this blog here: http://mrhaki.blogspot.com/2018/06/groovy-goodness-customizing-json-output.= html In your case you can do: {code} import groovy.json.* def generator =3D new JsonGenerator.Options() .addConverter(Locale) { Locale loc -> loc.toString() } .build() println generator.toJson([loc: Locale.FRANCE]) // =3D> {"loc":"fr_FR"} {code} > JsonOutput unable to serialize Locale object > -------------------------------------------- > > Key: GROOVY-8916 > URL: https://issues.apache.org/jira/browse/GROOVY-8916 > Project: Groovy > Issue Type: Bug > Components: groovy-runtime > Affects Versions: 2.4.15 > Reporter: S=C3=A9bastien Gadot > Priority: Minor > > Trying to serialize an object containing a Locale throws StackOverflowExc= eption > example : > =C2=A0 > =C2=A0 > {code:java} > JsonOutput.toJson([loc: Locale.FRANCE]) > // expected {"loc": "fr_FR"} > // got StackOverflowException > {code} > {code:java} > java.lang.StackOverflowError > at java.lang.reflect.InvocationTargetException.(InvocationTargetExc= eption.java:72) > at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccess= orImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:498) > at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:9= 8) > at groovy.lang.MetaBeanProperty.getProperty(MetaBeanProperty.java:59) > at groovy.lang.PropertyValue.getValue(PropertyValue.java:42) > at org.codehaus.groovy.runtime.DefaultGroovyMethods.getProperties(Default= GroovyMethods.java:474) > at groovy.json.JsonOutput.getObjectProperties(JsonOutput.java:338) > at groovy.json.JsonOutput.writeObject(JsonOutput.java:331) > at groovy.json.JsonOutput.writeMap(JsonOutput.java:469) > at groovy.json.JsonOutput.writeObject(JsonOutput.java:332) > at groovy.json.JsonOutput.writeMap(JsonOutput.java:469) > {code} > =C2=A0 -- This message was sent by Atlassian JIRA (v7.6.3#76005)