Done: https://github.com/openjson/openjson/commit/d2367f28cebd8f21c4a4e22faec4cab2f8a95982 Thanks for the test :)
BTW the test was modified: call new JSONObject(this) inside toJSONString() leads to StackOverflow On Sat, Apr 22, 2017 at 12:31 PM, Maxim Solodovnik <[email protected]> wrote: > There is no code to call this method > I'll check it later today > > WBR, Maxim > (from mobile, sorry for the typos) > > On Apr 22, 2017 02:01, "Sebastien" <[email protected]> wrote: > >> Hi again, >> >> The issue is that pojos implementing JSONString seems to not have their >> #toJSONString called during JSONObject#toString >> Looking at the code does not indicates an obvious reason, and for the >> weird >> one I have some difficulties to debug (caught the JSONException block in >> debug mode, probably due to the reflection, or maybe my eclipse is >> dying...) >> >> Here is a simple test case for whom would like to have a look: >> >> @Test >> public void testToString() >> { >> MyPojo1 myPojo1 = new MyPojo1(); >> MyPojo2 myPojo2 = new MyPojo2(); >> >> String json1 = new JSONObject(myPojo1).toString(); >> String json2 = new JSONObject(myPojo2).toString(); // FIXME: >> #toJSONString is never called >> >> Assert.assertEquals(json1, >> "{\"myProp1\":\"value1\",\"myProp2\":\"value2\"}"); >> Assert.assertEquals(json2, >> "{\"myProp3\":\"value3\",\"myProp4\":\"value4\",\"myProp5\": >> \"value5\"}"); >> } >> >> public static class MyPojo1 >> { >> private String myProp1 = "value1"; >> private String myProp2 = "value2"; >> >> public MyPojo1() >> { >> } >> >> public String getMyProp1() >> { >> return this.myProp1; >> } >> >> public String getMyProp2() >> { >> return this.myProp2; >> } >> } >> >> public static class MyPojo2 implements JSONString >> { >> private String myProp3 = "value3"; >> private String myProp4 = "value4"; >> >> public MyPojo2() >> { >> } >> >> public String getMyProp3() >> { >> return this.myProp3; >> } >> >> public String getMyProp4() >> { >> return this.myProp4; >> } >> >> @Override >> public String toJSONString() >> { >> JSONObject object = new JSONObject(this); >> object.put("myProp5", "value5"); >> >> return object.toString(); >> } >> } >> >> Best regards, >> Sebastien. >> >> On Fri, Apr 21, 2017 at 8:36 PM, Andrea Del Bene <[email protected]> >> wrote: >> >> > Take your time. Better be sure to have fixed possible problems with json >> > migration. >> > >> > >> > -- WBR Maxim aka solomax
