Created
June 13, 2011 13:52
-
-
Save yutax77/1022797 to your computer and use it in GitHub Desktop.
Collectionメンバー変数もJSON含めてシリアライズする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
import flexjson.JSONSerializer; | |
public class Human { | |
private String name; | |
private List<String> hobbies; //このフィールドをJSONに含めたい | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public List<String> getHobbies() { | |
return hobbies; | |
} | |
public void setHobbies(List<String> hobbies) { | |
this.hobbies = hobbies; | |
} | |
public String toJson(){ | |
return new JSONSerializer().exclude("*.class") | |
.include("hobbies")//明示的にincludeする! | |
.serialize(this); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
import flexjson.JSON; | |
import flexjson.JSONSerializer; | |
public class Human2 { | |
private String name; | |
private List<String> hobbies; //このフィールドをJSONに含めたい | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
@JSON //アノテーションを使えば、include()は不要 | |
public List<String> getHobbies() { | |
return hobbies; | |
} | |
public void setHobbies(List<String> hobbies) { | |
this.hobbies = hobbies; | |
} | |
public String toJson(){ | |
return new JSONSerializer().exclude("*.class") | |
.serialize(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment