在使用JSONObject时发现下面的问题:
package com.example;
import net.sf.json.JSONObject;
import org.junit.Test;
public class TestDozer {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public void test1() {
Map1 map1 = new Map1();
map1.put("username", "username");
map1.put("password", "password");
String s = JSONObject.fromObject(map1).toString();
System.out.println("s====>" + s);
// s====>{"username":"username","password":"password"}
}
@Test
public void test2() {
Map2 map1 = new Map2();
map1.put("password", "password");
map1.setUsername("username");
String s = JSONObject.fromObject(map1).toString();
System.out.println("s====>" + s);
// s====>{"password":"password"}
}
}
package com.example;
import java.util.HashMap;
public class Map1 extends HashMap {
}
package com.example;
import java.util.HashMap;
public class Map2 extends HashMap{
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
两次输出的json字符串不一样,让我很郁闷。