boonproject / boon

Simple opinionated Java for the novice to expert level Java Programmer. Low Ceremony. High Productivity.
http://richardhightower.github.io/site/Boon/Welcome.html
Apache License 2.0
520 stars 102 forks source link

boon saves empty attributes #355

Closed javamonkey79 closed 8 years ago

javamonkey79 commented 8 years ago

Consider this case:

public class Cat { public String name; public String type; public String sex; //... constructor, etc omitted for brevity } Cat mittens = new Cat("mittens", "calico", "");

In this case, Boon.toJson(mittens) will give us:

{ "name":"mittens", "type":"calico", "sex":"" }

Is there any way to ignore empty values? If not, will you consider a patch to allow for this?

javamonkey79 commented 8 years ago

Digging deeper, I would have expected this to work but did not:

JsonSerializer jsonSerializer = new JsonSerializerFactory().setIncludeEmpty(false).create(); System.out.println(jsonSerializer.serialize(mittens));

javamonkey79 commented 8 years ago

Ok, I see now that the includeEmpty property pertains to collections. I also see that StringSerializerImpl is where blank String checking would occur. However, it appears there is no way to inject in subclasses in to the factory? I think if you refactored the create method to read from protected methods, this would not be an issue: users could then subclass the factory and provide a version that suits their needs.

javamonkey79 commented 8 years ago

I've completed a simple version and issued a pull request: https://github.com/boonproject/boon/pull/356

javamonkey79 commented 8 years ago

I'm curious, is there something else I need to do here to get this rolled in?

RichardHightower commented 8 years ago

Let me look at your pull request. Been busy is all. :)

RichardHightower commented 8 years ago

I merged your request. It will get released the next time @slandelle does a release. If I remember correctly, I am not setup to do a release.

javamonkey79 commented 8 years ago

Cool, thanks for merging it in @RichardHightower . @slandelle do you have an ETA on a release?

slandelle commented 8 years ago

Done :)

@RichardHightower Are there some patches here that needs to be ported on https://github.com/advantageous/boon?

javamonkey79 commented 8 years ago

@RichardHightower wdyt about this type of behavior as default?

RichardHightower commented 8 years ago

Probably should be.

javamonkey79 commented 8 years ago

Ok, I'll submit a pull later then.

Sent with AquaMail for Android http://www.aqua-mail.com

On September 1, 2016 1:54:08 AM Richard Hightower notifications@github.com wrote:

Probably should be.

You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/boonproject/boon/issues/355#issuecomment-244017477

javamonkey79 commented 8 years ago

Ok, I've pushed my changes and submitted a pull request @RichardHightower

RichardHightower commented 7 years ago

looking now