Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion : Re: Exclusion on Value. (Kind of ExclusionStrategy)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Inderjeet Singh  
View profile   Translate to Translated (View Original)
 More options Jul 25 2012, 4:49 pm
From: Inderjeet Singh <inder...@gmail.com>
Date: Wed, 25 Jul 2012 13:49:51 -0700 (PDT)
Local: Wed, Jul 25 2012 4:49 pm
Subject: Re: [google-gson:1735]: Re: Exclusion on Value. (Kind of ExclusionStrategy)

Can you file a feature request on the Gson project page with the following
options?
We will evaluate it for our next release.

Thanks
Inder
http://www.singhinderjeet.com/

On Thursday, July 19, 2012 1:45:15 PM UTC-7, Jean-Marc Spaggiari wrote:

> I like options 1 and 3.

> I think the 3rd one will really be a good enhancement.

> Regarding the efficiency, if those data has to be transfered over a
> network, you might loose checks time what you are going to save in
> transfert and storage time.

> For now, what I'm doing is "simply" parsing the output string to
> remove the default values by comparing them from a brand new instance
> Gson string. So having something like @GsonExcludeDefaultValue might
> help a lot.

> 2012/7/19, Maaartin <maaarti...@gmail.com>:
> > On Tuesday, July 3, 2012 8:08:01 PM UTC+2, Jean-Marc Spaggiari wrote:
> >> With the interface ExclusionStrategy it's possible to exclude a field
> to
> > be serialized based on it's title. But is there a way to filter based on
> > the value?

> > +1, that's what I just wanted to ask. My case is nearly the same, except
> > for `{sizeLimit: 9223372036854775807}` looking even worse. I don't want
> to
> > use -1 there as `Long.MAX_VALUE` is the natural choice here, nor I want
> to
> > use null as `Long` instead of `long`.

> > On Friday, July 13, 2012 2:14:55 AM UTC+2, Inderjeet Singh wrote:
> >> You dont have the option to exclude based on the value in an exclusion
> > strategy. Gson tries to achieve efficiency by making decisions to
> > include/exclude fields once per class (while finding its type adapter).
> > Providing you ability to select based on value would run counter to
> that.

> > Concerning the efficiency I beg to differ. Sure, excluding fields on the
> > class basis is good for efficiency, but I don't think you lose any when
> you

> > do an additional check if a field not-excluded on the per-class bases
> could

> > be excluded based on its value.

> >> BTW, You can write a custom type adapter for MyData that excludes
> > temperature if it is -1. Is that not a good enough option?

> > I'd strongly prefer something like

> > class MyData {
> >     @GsonExcludeIfValue(Long.MAX_VALUE)
> >     private long sizeLimit = Long.MAX_VALUE;
> >     @GsonExcludeIfValue(-1)
> >     private int temperature = -1;
> > }

> > or maybe

> > class MyData {
> >     @GsonDefaultValuesProvider
> >     private static defaultInstance = new MyData();
> >     private sizeLimit = Long.MAX_VALUE;
> >     private int temperature = -1;
> > }

> > where each value would be tested against the value in defaultInstance,
> or
> > maybe

> > @GsonExcludeDefaultValue
> > class MyData {
> >     private sizeLimit = Long.MAX_VALUE;
> >     private int temperature = -1;
> > }

> > where GSon would determine the default values by deserializing an object
> > with missing values. The last idea mightn't work.

> > --
> > You received this message because you are subscribed to the Google
> Groups
> > "google-gson" group.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msg/google-gson/-/wPmRfO1CZDkJ.
> > To post to this group, send email to google-gson@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-gson+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/google-gson?hl=en.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.