前人未踏の領域へ Androidアプリ開発編

Androidアプリ開発に関する調査メモ置き場。古い記事にはアプリ以外も含まれます。

Jackson+SAStrutsでAjaxする

  • ObjectMapper.writeValueAsString()でJSON文字列
  • ResponseUtil.write()で結果を出力
  • ContentTypeは"application/json" とする
public class ItemAction {
	private static final String APPLICATION_JSON = "application/json";

	@Execute(validator = false)
	public String index() {
		try {
                       Hoge hoge = new Hoge(); //POJO

			ObjectMapper mapper = new ObjectMapper();
			ResponseUtil.write(mapper.writeValueAsString(hoge),APPLICATION_JSON);
		} catch (JsonProcessingException e) {
			//TODO エラー用JSON
		}
		return null;
	}
}