groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Kleeh <james.kl...@gmail.com>
Subject Re: 2.5 JsonBuilder Converters thoughts
Date Sat, 05 Nov 2016 22:38:04 GMT
John,

PR submitted: https://github.com/apache/groovy/pull/457 <https://github.com/apache/groovy/pull/457>

James

> On Nov 4, 2016, at 12:30 PM, John Wagenleitner <john.wagenleitner@gmail.com> wrote:
> 
> I think there is consensus and a PR would be great.
> 
> On Fri, Nov 4, 2016 at 9:23 AM, James Kleeh <james.kleeh@gmail.com <mailto:james.kleeh@gmail.com>>
wrote:
> Do we have any consensus on this? Should I submit a PR with the change?
> 
> > On Oct 28, 2016, at 6:51 AM, Graeme Rocher <graeme.rocher@gmail.com <mailto:graeme.rocher@gmail.com>>
wrote:
> >
> > one thing to note. I would assume if we allow JsonOutput.unescaped it
> > would the convert method would have to return Object? Currently the
> > JsonUnescaped type doesn't implement CharSequence
> >
> > If that is the case it may also be interesting to support return types
> > of Writable since.
> >
> > Cheers
> >
> > On Fri, Oct 28, 2016 at 12:46 PM, Graeme Rocher <graeme.rocher@gmail.com <mailto:graeme.rocher@gmail.com>>
wrote:
> >> Yeah I agree JsonOutput.unescaped allows the same flexibility without
> >> compromising the most common use case.
> >>
> >> Cheers
> >>
> >> On Tue, Oct 25, 2016 at 10:32 PM, John Wagenleitner
> >> <john.wagenleitner@gmail.com <mailto:john.wagenleitner@gmail.com>>
wrote:
> >>> On Tue, Oct 25, 2016 at 12:07 PM, James Kleeh <james.kleeh@gmail.com
<mailto:james.kleeh@gmail.com>> wrote:
> >>>>
> >>>> Currently if one were to register a converter with options like so:
> >>>>
> >>>> JsonGenerator.Options options = new JsonGenerator.Options()
> >>>> options.addConverter(MyCustomType) { MyCustomType mct ->
> >>>>    mct.name <http://mct.name/>
> >>>> }
> >>>>
> >>>>
> >>>> Assuming “mct.name <http://mct.name/>” returns a string, it
will be output without quotes
> >>>> because of:
> >>>>
> >>>> Converter converter = findConverter(objectClass);
> >>>> if (converter != null) {
> >>>>    writeRaw(converter.convert(object, key), buffer);
> >>>>    return;
> >>>> }
> >>>>
> >>>> I’d be curious to hear what the use case is for outputting the data
as
> >>>> raw. I think the percentage of users that would prefer to have their
data
> >>>> further processed by that method would vastly outnumber the ones that
do
> >>>> not.
> >>>>
> >>>> I think something like this would be a better solution:
> >>>>
> >>>> Converter converter = findConverter(objectClass);
> >>>> if (converter != null) {
> >>>>    object = converter.convert(object, key);
> >>>> }
> >>>>
> >>>> Thoughts?
> >>>
> >>>
> >>>
> >>> I had aimed for making it as flexible as possible and purposefully had it
> >>> not participate in further processing to avoid surprises and be able to
> >>> output JSON that otherwise wouldn't be possible due to the way the generator
> >>> was already configured (nulls or being able to write out a number such as
> >>> 9.3e7).
> >>>
> >>> I like your suggestion and think the flexibility could still be accomplished
> >>> using JsonOutput.unescaped; and since 2.5 isn't out yet there's still time
> >>> to refine how it works.
> >>>
> >>> I also would like to hear what others think.
> >>>
> >>> John
> >>
> >>
> >>
> >> --
> >> Graeme Rocher
> >
> >
> >
> > --
> > Graeme Rocher
> 
> 


Mime
View raw message