Created
September 28, 2012 15:59
-
-
Save ispern/3800673 to your computer and use it in GitHub Desktop.
play.libs.Jsonを継承してJacksonでDateFormatを指定する。
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 org.codehaus.jackson.JsonNode; | |
import org.codehaus.jackson.map.ObjectMapper; | |
import play.libs.Json; | |
import java.text.SimpleDateFormat; | |
public class JsonEx extends Json { | |
/** | |
* Convert an object to JsonNode. | |
* | |
* @param data Value to convert in Json. | |
*/ | |
public static JsonNode toJson(final Object data) { | |
try { | |
ObjectMapper mapper = new ObjectMapper(); | |
mapper.setDateFormat(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")); | |
return mapper.valueToTree(data); | |
} catch(Exception e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment