You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by li...@apache.org on 2009/02/17 23:16:36 UTC

svn commit: r745275 - /incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java

Author: lindner
Date: Tue Feb 17 22:16:36 2009
New Revision: 745275

URL: http://svn.apache.org/viewvc?rev=745275&view=rev
Log:
SHINDIG-888 | Reduce json output for people requests only generate isOwner/isViewer output if they are true.

Modified:
    incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java

Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java?rev=745275&r1=745274&r2=745275&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java Tue Feb 17 22:16:36 2009
@@ -189,15 +189,20 @@
       try {
         Object value = entry.getValue().invoke(pojo);
         if (value != null) {
-          // Drop null values.
-          if (firstDone) {
-            buf.append(',');
-          } else {
-            firstDone = true;
+          String attribute = entry.getKey();
+
+          // Common use case isOwner/isViewer should not be set unless true
+          if (!((attribute.equals("isOwner") || attribute.equals("isViewer")) && value.equals(Boolean.FALSE))) {
+            // Drop null values.
+            if (firstDone) {
+              buf.append(',');
+            } else {
+              firstDone = true;
+            }
+            appendString(buf, attribute);
+            buf.append(':');
+            append(buf, value);
           }
-          appendString(buf, entry.getKey());
-          buf.append(':');
-          append(buf, value);
         }
       } catch (IllegalArgumentException e) {
         // Shouldn't be possible.



Re: svn commit: r745275 - /incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java

Posted by Louis Ryan <lr...@google.com>.
I think thats what I was suggesting :)

On Tue, Feb 17, 2009 at 6:36 PM, Paul Lindner <pl...@hi5.com> wrote:

> I'm not sure where else we could put this code, but I think I might have an
> idea.....
>
> Right now we use JsonSerializer to output the Person objects that get
> generate that code.  That seemed to be the only place to put in this
> optimization.  however on second look it appears that we throw out null
> values.  So what we can do is change the logic of getIsOwner and getIsViewer
> to only return Boolean.TRUE when true and null otherwise.
>
> thoughts?
>
>
>
>
> On Feb 17, 2009, at 6:26 PM, Louis Ryan wrote:
>
>  Paul
>>
>> I dont think common is the correct place to put that code as it is very
>> social API specific. Why not just change the model to use Boolean instead
>> of
>> boolean?
>>
>> -Louis
>>
>> On Tue, Feb 17, 2009 at 2:16 PM, <li...@apache.org> wrote:
>>
>>  Author: lindner
>>> Date: Tue Feb 17 22:16:36 2009
>>> New Revision: 745275
>>>
>>> URL: http://svn.apache.org/viewvc?rev=745275&view=rev
>>> Log:
>>> SHINDIG-888 | Reduce json output for people requests only generate
>>> isOwner/isViewer output if they are true.
>>>
>>> Modified:
>>>
>>>
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java
>>>
>>> Modified:
>>>
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java
>>> URL:
>>>
>>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java?rev=745275&r1=745274&r2=745275&view=diff
>>>
>>>
>>> ==============================================================================
>>> ---
>>>
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java
>>> (original)
>>> +++
>>>
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java
>>> Tue Feb 17 22:16:36 2009
>>> @@ -189,15 +189,20 @@
>>>     try {
>>>       Object value = entry.getValue().invoke(pojo);
>>>       if (value != null) {
>>> -          // Drop null values.
>>> -          if (firstDone) {
>>> -            buf.append(',');
>>> -          } else {
>>> -            firstDone = true;
>>> +          String attribute = entry.getKey();
>>> +
>>> +          // Common use case isOwner/isViewer should not be set unless
>>> true
>>> +          if (!((attribute.equals("isOwner") ||
>>> attribute.equals("isViewer")) && value.equals(Boolean.FALSE))) {
>>> +            // Drop null values.
>>> +            if (firstDone) {
>>> +              buf.append(',');
>>> +            } else {
>>> +              firstDone = true;
>>> +            }
>>> +            appendString(buf, attribute);
>>> +            buf.append(':');
>>> +            append(buf, value);
>>>         }
>>> -          appendString(buf, entry.getKey());
>>> -          buf.append(':');
>>> -          append(buf, value);
>>>       }
>>>     } catch (IllegalArgumentException e) {
>>>       // Shouldn't be possible.
>>>
>>>
>>>
>>>
>

Re: svn commit: r745275 - /incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java

Posted by Paul Lindner <pl...@hi5.com>.
I'm not sure where else we could put this code, but I think I might  
have an idea.....

Right now we use JsonSerializer to output the Person objects that get  
generate that code.  That seemed to be the only place to put in this  
optimization.  however on second look it appears that we throw out  
null values.  So what we can do is change the logic of getIsOwner and  
getIsViewer to only return Boolean.TRUE when true and null otherwise.

thoughts?



On Feb 17, 2009, at 6:26 PM, Louis Ryan wrote:

> Paul
>
> I dont think common is the correct place to put that code as it is  
> very
> social API specific. Why not just change the model to use Boolean  
> instead of
> boolean?
>
> -Louis
>
> On Tue, Feb 17, 2009 at 2:16 PM, <li...@apache.org> wrote:
>
>> Author: lindner
>> Date: Tue Feb 17 22:16:36 2009
>> New Revision: 745275
>>
>> URL: http://svn.apache.org/viewvc?rev=745275&view=rev
>> Log:
>> SHINDIG-888 | Reduce json output for people requests only generate
>> isOwner/isViewer output if they are true.
>>
>> Modified:
>>
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/JsonSerializer.java
>>
>> Modified:
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/JsonSerializer.java
>> URL:
>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java?rev=745275&r1=745274&r2=745275&view=diff
>>
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> ---
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/JsonSerializer.java
>> (original)
>> +++
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/JsonSerializer.java
>> Tue Feb 17 22:16:36 2009
>> @@ -189,15 +189,20 @@
>>      try {
>>        Object value = entry.getValue().invoke(pojo);
>>        if (value != null) {
>> -          // Drop null values.
>> -          if (firstDone) {
>> -            buf.append(',');
>> -          } else {
>> -            firstDone = true;
>> +          String attribute = entry.getKey();
>> +
>> +          // Common use case isOwner/isViewer should not be set  
>> unless
>> true
>> +          if (!((attribute.equals("isOwner") ||
>> attribute.equals("isViewer")) && value.equals(Boolean.FALSE))) {
>> +            // Drop null values.
>> +            if (firstDone) {
>> +              buf.append(',');
>> +            } else {
>> +              firstDone = true;
>> +            }
>> +            appendString(buf, attribute);
>> +            buf.append(':');
>> +            append(buf, value);
>>          }
>> -          appendString(buf, entry.getKey());
>> -          buf.append(':');
>> -          append(buf, value);
>>        }
>>      } catch (IllegalArgumentException e) {
>>        // Shouldn't be possible.
>>
>>
>>


Re: svn commit: r745275 - /incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java

Posted by Louis Ryan <lr...@google.com>.
Paul

I dont think common is the correct place to put that code as it is very
social API specific. Why not just change the model to use Boolean instead of
boolean?

-Louis

On Tue, Feb 17, 2009 at 2:16 PM, <li...@apache.org> wrote:

> Author: lindner
> Date: Tue Feb 17 22:16:36 2009
> New Revision: 745275
>
> URL: http://svn.apache.org/viewvc?rev=745275&view=rev
> Log:
> SHINDIG-888 | Reduce json output for people requests only generate
> isOwner/isViewer output if they are true.
>
> Modified:
>
>  incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java
>
> Modified:
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java?rev=745275&r1=745274&r2=745275&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java
> (original)
> +++
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonSerializer.java
> Tue Feb 17 22:16:36 2009
> @@ -189,15 +189,20 @@
>       try {
>         Object value = entry.getValue().invoke(pojo);
>         if (value != null) {
> -          // Drop null values.
> -          if (firstDone) {
> -            buf.append(',');
> -          } else {
> -            firstDone = true;
> +          String attribute = entry.getKey();
> +
> +          // Common use case isOwner/isViewer should not be set unless
> true
> +          if (!((attribute.equals("isOwner") ||
> attribute.equals("isViewer")) && value.equals(Boolean.FALSE))) {
> +            // Drop null values.
> +            if (firstDone) {
> +              buf.append(',');
> +            } else {
> +              firstDone = true;
> +            }
> +            appendString(buf, attribute);
> +            buf.append(':');
> +            append(buf, value);
>           }
> -          appendString(buf, entry.getKey());
> -          buf.append(':');
> -          append(buf, value);
>         }
>       } catch (IllegalArgumentException e) {
>         // Shouldn't be possible.
>
>
>