groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Wagenleitner <john.wagenleit...@gmail.com>
Subject Re: 2.5 JsonBuilder Converters thoughts
Date Tue, 25 Oct 2016 20:32:08 GMT
On Tue, Oct 25, 2016 at 12:07 PM, James Kleeh <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
> }
>
>
> Assuming “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

Mime
View raw message