You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by britter <gi...@git.apache.org> on 2015/04/30 20:17:19 UTC

[GitHub] commons-lang pull request: fix JsonToStringStyle

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.
---