Comments (7)
[deleted comment]
from json-io.
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.
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.
Looking into this now.
Original comment by [email protected]
on 1 Oct 2013 at 5:37
- Changed state: Accepted
from json-io.
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.
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.
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)
- Abbreviation for package path HOT 1
- Import library? HOT 3
- Serializing Maps as Simple JSON Maps HOT 2
- serializing an empty ArrayList produces {} instead of [] HOT 4
- java.io.IOException: Class instance 'Foo' could not be created at position 10533 HOT 3
- Access to JsonObject.target required in custom JsonClassReaders HOT 1
- Serializing breaks for java.util.Date subclasses HOT 2
- In Java 7, the Throwable type contains java.util.Collections$UnmodifiableRandomAccessList, which does not allow a null constructor arg HOT 4
- cloneObject(String s) HOT 1
- JsonWriter not working as expected for single string input; works for other types HOT 1
- IllegalAccessException HOT 1
- maybe unnecessary call of convertParsedMapsToJava inside JsonReader.readObject()
- Feature request: add a optional fallback type parameter for the toplevel json container to JsonReader.jsonToJava(json); HOT 1
- loadClass(name) raises ClassNotFound Exception although Class exists / solution available
- json for enum includes private fields, causes error when parsing
- JsonWriter.objectToJson breaks on HashMap<Double, Double>
- Feature request: Totally disable '@type' field
- Double.NaN not handled correctly. HOT 1
- Float NaN value causes token exception (expects null)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-io.