juneau-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig Russell <craig.russ...@oracle.com>
Subject Re: Adding builder classes for serializers and parsers.
Date Fri, 03 Mar 2017 18:20:29 GMT
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



Mime
View raw message