Menu

#90 toBean does not recognize write method when write method's

open
aalmiray
None
5
2009-06-09
2009-05-27
LI Daobing
No

toBean does not recognize write method when write method's return value is not void.

for example, the following testcase[1], there are two class B and A, B's setter does not return void, and toBean does not work for it.

please support this, thanks.

the output of the testcase:
May 27, 2009 4:53:34 PM net.sf.json.JSONObject toBean
WARNING: Property 'a' of class com.kingsoft.bgd.service.GaeServiceImplTest$B has no write method. SKIPPED.
0
1

[1]
public class JsonTest {

@Test
public void testJson() {
JSONObject jsonObject = JSONObject.fromObject("{a:1}");
B b = (B) jsonObject.toBean(jsonObject, B.class);
System.out.println(b.getA());
A a = (A) jsonObject.toBean(jsonObject, A.class);
System.out.println(a.getA());
}

public static class B {
private int a;

public B setA(int a) {
this.a = a;
return this;
}

public int getA() {
return a;
}

}

public static class A {
private int a;

public void setA(int a) {
this.a = a;
}

public int getA() {
return a;
}

}

Discussion

  • LI Daobing

    LI Daobing - 2009-05-27
    • summary: to --> toBean does not recognize write method when write method's
     
  • aalmiray

    aalmiray - 2009-06-09
    • assigned_to: nobody --> aalmiray
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.