juneau-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Bognar <james.bog...@salesforce.com>
Subject Re: Adding builder classes for serializers and parsers.
Date Fri, 10 Mar 2017 02:35:19 GMT
Update....

I'm close to delivering this.

Here's what it will look like to create a new serializer:

JsonSerializer n = new JsonSerializerBuilder(s)
   .quoteChar('\'')
   .useWhitespace(false)
   .build();

Shortcut methods are provided for common builder setters.
This is an equivalent to the above:

JsonSerializer n = new JsonSerializerBuilder(s).sq().ws().build();

To clone, a builder() method has been added to serializers and parsers:

JsonSerializer n = JsonSerializer.DEFAULT.builder().sq().ws().build();


I've introduced RestClientBuilder, SerializerGroupBuilder, and
ParserGroupBuilder classes as well.


On Fri, Mar 3, 2017 at 2:02 PM, James Bognar <james.bognar@salesforce.com>
wrote:

> > Would the builder be able to take a parameter? So to clone the
> serializer s but change the UseWhitespace setting:
>
> Yea...I can include that.
>
> You'll also be able to specify a subclass in the build method...
> JsonSerializer n = new JsonSerializerBuilder().useWhitespace(false).build(
> JsonSerializer.Simple.class);
>
> On Fri, Mar 3, 2017 at 1:20 PM, Craig Russell <craig.russell@oracle.com>
> wrote:
>
>> From left field…
>>
>> > On Mar 3, 2017, at 5:14 AM, James Bognar <jamesbognar@apache.org>
>> wrote:
>> >
>> > Hi all,
>> >
>> > I'm thinking about changing the way serializers and parsers are
>> constructed
>> > by creating builder classes.  I wanted to run it by the team first
>> though.
>> >
>> > Creating a custom serializer would look like this...
>> >
>> > JsonSerializer s = new
>> > JsonSerializerBuilder().useWhitespace(true).trimNulls(true).build();
>>
>> I like this pattern. I’m not a huge fan of setXXX when xxx is a perfectly
>> good understandable concept
>>
>> > ...instead of...
>> > JsonSerializer s = new
>> > JsonSerializer().setUseWhitespace(true).setTrimNulls(true).lock();
>> >
>> > With this approach I can make the fields final and eliminate the
>> read-write
>> > locks from the classes.
>> >
>> > The DEFAULT serializers and parsers are not going away.  You won't be
>> able
>> > to clone and modify them anymore though.
>> >
>> > Any thoughts?
>>
>> Would the builder be able to take a parameter? So to clone the serializer
>> s but change the UseWhitespace setting:
>>
>> JsonSerializer n = new
>> JsonSerializerBuilder(s).useWhitespace(false).build();
>>
>> Craig
>>
>> Craig L Russell
>> clr@apache.org
>>
>>
>>
>
>
> --
> James Bognar
>



-- 
James Bognar

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message