Coder Social home page Coder Social logo

Comments (7)

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
[deleted comment]

from json-io.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
The test case below works just fine.  If you can show me a case where there is 
an issue, please send it.

static class Outer
    {
        String name;
        class Inner
        {
            String name;
        };
        Inner foo;
    }

    public void testNestedWithSameMemberName() throws Exception
    {
        Outer outer = new Outer();
        outer.name = "Joe Outer";
        // TestJsonReaderWriter.A.B b = a.new B();
        TestJsonReaderWriter.Outer.Inner inner = outer.new Inner();
        inner.name = "Jane Inner";
        outer.foo = inner;

        String json = getJsonString(outer);
        println("json = " + json);

        Outer x = (Outer) readJsonObject(json);
        assertEquals(x.name, "Joe Outer");
        assertEquals(x.foo.name, "Jane Inner");
    }

Original comment by [email protected] on 29 Sep 2013 at 3:46

  • Changed state: Invalid

from json-io.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
public class Parent {
    private String name;

    public String getParentName() {
        return name;
    }

    public void setParentName(String name) {
        this.name = name;
    }
}

public class Child extends Parent {
    private String name;

    public String getChildName() {
        return name;
    }

    public void setChildName(String name) {
        this.name = name;
    }
}

public class ChildTest {
    @Test
    public void test() throws IOException {
        Child child = new Child();
        child.setChildName("child");
        child.setParentName("parent");

        String json = JsonWriter.objectToJson(child);
        Child roundTrip = (Child) JsonReader.jsonToJava(json);

        System.out.println(json); //note missing Child name

        assertEquals(child.getParentName(), roundTrip.getParentName());
        assertEquals(child.getChildName(), roundTrip.getChildName());
    }
}

Output:
{"@type":"Child","name":"parent"}
java.lang.AssertionError: expected:<child> but was:<null>

It is assumed that no 2 private fields will have the same name which is not a 
safe assumption.

Original comment by [email protected] on 30 Sep 2013 at 8:13

from json-io.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
Looking into this now.

Original comment by [email protected] on 1 Oct 2013 at 5:37

  • Changed state: Accepted

from json-io.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
This issue has been fixed and is available in the latest source code on GitHub. 
 The next release (either 2.2.32 or 2.3.0) will include this fix.

Original comment by [email protected] on 1 Oct 2013 at 8:04

  • Changed state: Fixed

from json-io.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
I should add that the way this is addressed, is that the first field 
encountered retains it's short name, in your example, the word 'name.'  If 
another field in the class hierarchy has the name, it's is written into the 
JSON stream as 'fully.qualified.class.fieldName'.  All copies then get written 
out, and the reader, reads these in just fine.  This is support for both 
jsonToJava, and jsonToMaps, both read in, and written out.

Original comment by [email protected] on 1 Oct 2013 at 10:36

from json-io.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 26, 2024
This issue was officially corrected in the 2.2.32 json-io release.

Original comment by [email protected] on 13 Nov 2013 at 1:20

  • Changed state: Done

from json-io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.