[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-dev
Subject:    [GitHub] commons-lang pull request: fix JsonToStringStyle
From:       britter <git () git ! apache ! org>
Date:       2015-04-30 18:17:19
Message-ID: 20150430181719.EA92AE0061 () git1-us-west ! apache ! org
[Download RAW message or body]

Github user britter commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/74#discussion_r29455380
  
    --- Diff: src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java ---
    @@ -2568,13 +2573,13 @@ protected void appendDetail(StringBuffer buffer, String \
fieldName, Object value)  return;
                 }
     
    -            if (value.getClass() == String.class) {
    +            if (value instanceof Number || value.getClass() == Boolean.class) {
     
    -                appendValueAsString(buffer, (String)value);
    +                buffer.append(value);
                     return;
                 }
     
    -            buffer.append(value);
    +            appendValueAsString(buffer, value.toString());
    --- End diff --
    
    I don't think this is correct for nested object structures. Suppose we have the \
following class structure:  
    ```java
    public class Person {
       private String name;
       private Address address;
    }
    
    public class Address {
       private String city;
       private String zip;
    }
    ```
    
    Translating this to JavaScript/JSON should look like this if both, Person and \
Address use the JsonToStringStyle for their equals method:  
    ```JavaScript
    {
       "name": "Peter",
       "address": {
          "city": "New York",
          "zip": "10026"
       }
    }
    ```
    
    If we apply this fix, the result will look like this:
    
    ```JavaScript
    {
       "name": "Peter",
       "address": "{
          "city": "New York",
          "zip": "10026"
       }"
    }
    ```
    
    Note the additional double quotes around the address object.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic