{"id":1520,"date":"2015-05-29T01:54:46","date_gmt":"2015-05-28T16:54:46","guid":{"rendered":"http:\/\/kazu.tv\/blog\/?p=1520"},"modified":"2015-05-29T02:03:07","modified_gmt":"2015-05-28T17:03:07","slug":"play-framework-jspath-readnullable-behavior","status":"publish","type":"post","link":"https:\/\/kazu.tv\/blog\/2015\/05\/29\/play-framework-jspath-readnullable-behavior\/","title":{"rendered":"Play! framework\u306eJsPath.readNullable\u306e\u6319\u52d5"},"content":{"rendered":"<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p>Play! framework \u306e JSON \u30e9\u30a4\u30d6\u30e9\u30ea\u3063\u3066\u3001\u6163\u308c\u308c\u3070\u307e\u3041\u666e\u901a\u306b\u4f7f\u3048\u308b\u3051\u3069\u3001\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u304c\u30a4\u30de\u30a4\u30c1\u3060\u3057\u3001\u3084\u308a\u305f\u3044\u3053\u3068\u3092\u3069\u3046\u66f8\u3051\u3070\u3044\u3044\u304b\u304c\u5206\u304b\u3089\u306a\u304f\u3066\u6642\u9593\u3092\u4f7f\u3046\u3053\u3068\u304c\u591a\u3044\u3002<\/p>\n<p>\u4eca\u56de\u66f8\u304f\u306e\u306f\u3001JSON\u30c7\u30fc\u30bf\u3067\u3042\u308b\u8981\u7d20\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306b\u305d\u308c\u3092\u3069\u3046\u6271\u3046\u304b\u3001\u3068\u3044\u3046\u8a71\u984c\u3002<\/p>\n<p>\u300c\u306a\u3093\u3060 readNullable \u4f7f\u3046\u3060\u3051\u3067\u3057\u3087\uff1f\u300d<\/p>\n<p>\u3068\u601d\u3046\u4eba\u3082\u3044\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u3002\u307e\u3041\u5b9f\u969b\u306b\u306f\u305d\u3046\u306a\u3093\u3060\u3051\u3069\u3001readNullable \u306e\u6319\u52d5\u304c\u82e5\u5e72\u5206\u304b\u308a\u306b\u304f\u304b\u3063\u305f\u306e\u3067\u3001\u305d\u308c\u306b\u3064\u3044\u3066\u3002<\/p>\n<h2>\u3084\u308a\u305f\u3044\u3053\u3068<\/h2>\n<p>JSON\u30c7\u30fc\u30bf\u3067\u3001\u3042\u308b\u8981\u7d20\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u3068\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u304c\u8003\u3048\u3089\u308c\u308b\u3068\u304d\u3001\u305d\u306e\u8981\u7d20\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u306f Some \u3001\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306f None \u3068\u3057\u3066\u30d1\u30fc\u30b9\u3057\u305f\u3044\u3002<\/p>\n<p>\u5177\u4f53\u7684\u306a\u4f8b\u3067\u8aac\u660e\u3059\u308b\u3068\u3001Facebook API\u304b\u3089\u4ee5\u4e0b\u306e\u3088\u3046\u306aJSON\u304c\u8fd4\u3063\u3066\u304f\u308b\u3068\u3059\u308b\u3002\u5185\u5bb9\u306f\u3042\u308bFacebook\u30b0\u30eb\u30fc\u30d7\u3078\u306e\u66f8\u304d\u8fbc\u307f\u3002<\/p>\n<p><!--more--><\/p>\n<pre class=\"brush: plain\">{\r\n  \"data\": [\r\n    {\r\n  \u00a0\u00a0\u00a0 \"message\" : \"Hi, thanks for the invite!\",\r\n   \u00a0\u00a0 \"from\" : {\r\n\u00a0\u00a0  \u00a0\u00a0\u00a0 \"id\" : \"100000\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0   \"name\" : \"Test User\"\r\n\u00a0\u00a0\u00a0   },\r\n      \"to\": {\r\n        \"data\": [\r\n          {\r\n            \"id\": \"123456789\",\r\n            \"name\": \"K's Secret Group\"\r\n          }\r\n        ]\r\n      },\r\n      \"comments\": {\r\n        \"data\": [\r\n          {\r\n            \"id\": \"12345_67890\",\r\n            \"from\": {\r\n              \"id\": \"2345678901\",\r\n              \"name\": \"Kazu\"\r\n            },\r\n            \"message\": \"\u5143\u6c17\uff1f\",\r\n            \"created_time\": \"2014-10-21T02:16:10+0000\"\r\n          }\r\n        ],\r\n        \"paging\": {\r\n          \"previous\": \"https:\/\/graph.facebook.com\/previous\",\r\n          \"next\": \"https:\/\/graph.facebook.com\/next\"\r\n        }\r\n      }\r\n    }\r\n  ]\r\n}\r\n<\/pre>\n<p>comments \u3063\u3066\u8981\u7d20\u306e\u4e0b\u306b\u30b3\u30e1\u30f3\u30c8\u304c\u4e26\u3073\uff08\u4e0a\u306eJSON\u3067\u306f1\u4ef6\u306e\u307f\uff09\u3001\u4ef6\u6570\u304c\u591a\u3044\u5834\u5408\u306f paging \u3068\u3044\u3046\u8981\u7d20\u306e\u4e2d\u306b\u300c\u524d\u3078\u300d\u3068\u300c\u6b21\u3078\u300d\u306e\u30ea\u30f3\u30af\u304c\u542b\u307e\u308c\u308b\u3001\u3068\u3044\u3046\u69cb\u9020\u306b\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n<h2>\u65b9\u6cd5<\/h2>\n<h3>readNullable \u3092\u4f7f\u3046<\/h3>\n<p>\u305f\u3060\u3001\u66f8\u304d\u8fbc\u307f\u306b\u306f\u30b3\u30e1\u30f3\u30c8\u304c\u4ed8\u304b\u306a\u3044\u5834\u5408\u3082\u3042\u308a\u3001\u305d\u306e\u6642\u306b\u306f comments \u8981\u7d20\u81ea\u4f53\u304c\u5b58\u5728\u3057\u306a\u3044\u3002\u3068\u308a\u3042\u3048\u305a\u4ed6\u306e\u8981\u7d20\u3092\u7121\u8996\u3057\u3066\u3001next\u306eURL\u3060\u3051\u3092\u53d6\u308a\u51fa\u3057\u305f\u3044\u3068\u3059\u308b\u3002\u305d\u3082\u305d\u3082JSON\u304b\u3089\u5024\u3092\u53d6\u308a\u51fa\u3059\u65b9\u6cd5\u304c\u4f55\u901a\u308a\u304b\u3042\u308b\u304c\u3001\u3053\u3053\u3067\u306f <a href=\"https:\/\/www.playframework.com\/documentation\/2.3.x\/ScalaJsonCombinators\" target=\"_blank\">Reads\u3092\u4f7f\u3046\u65b9\u6cd5<\/a>\u3067\u3084\u308b\u3053\u3068\u3068\u3059\u308b\u3002<\/p>\n<pre class=\"brush: scala;\">case class NextCommentsUrl(url: Option[String])\r\nval urlReads: Reads[NextCommentsUrl] = (\r\n  (__ \\ \"comments\" \\ \"paging\" \\ \"next\").readNullable[String]\r\n)(NextCommentsUrl)\r\n<\/pre>\n<p>\u3068\u3084\u308b\u3068\u3053\u308d\u3060\u3051\u3069\u3001\u3053\u308c\u3060\u3068\u3046\u307e\u304f\u3044\u304b\u306a\u3044\u3002<\/p>\n<p><a href=\"https:\/\/groups.google.com\/forum\/#!topic\/play-framework\/syIGGbr5Fwk\" target=\"_blank\">\u3053\u306e\u8fba<\/a>\u3092\u898b\u308b\u3068\u3001 readNullable \u306f\u89aa\u8981\u7d20\u304c\u5b58\u5728\u3057\u3066\u3044\u306a\u3044\u3068\u30c0\u30e1\u3089\u3057\u3044\u3002\u4eca\u56de\u306f comments \u81ea\u4f53\u304c\u5b58\u5728\u3057\u306a\u3044\u306e\u3067\u3001\u3053\u308c\u3060\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3002<\/p>\n<h3>orElse \u3067\u3064\u306a\u3050\u30cf\u30c3\u30af\u3067<\/h3>\n<p>\u7d50\u5c40\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30cf\u30c3\u30af\u3067\u4e57\u308a\u5207\u308b\u3053\u3068\u304c\u3067\u304d\u305f\u3051\u3069\u3002<\/p>\n<pre class=\"brush: scala;\">case class NextCommentsUrl(url: Option[String])\r\nval urlReads: Reads[NextCommentsUrl] = (\r\n  (__ \\ \"comments\" \\ \"paging\" \\ \"next\").readNullable[String]\r\n    orElse (__ \\ \"comments\" \\ \"paging\").readNullable[String]\r\n    orElse (__ \\ \"comments\").readNullable[String])\r\n)(NextCommentsUrl)\r\n<\/pre>\n<h2>\u00a0\u307e\u3068\u3081\u30fb\u611f\u60f3<\/h2>\n<p>JsPath.readNullable \u306f\u3001\u5bfe\u8c61\u8981\u7d20\u304c\u5b58\u5728\u3057\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308b\u3068\u304d\u306b\u4f7f\u3046\u304c\u3001\u5bfe\u8c61\u8981\u7d20\u306e\u89aa\u8981\u7d20\u3082\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306b\u306f\u3046\u307e\u304f\u3044\u304b\u306a\u3044\u3002\u305d\u306e\u5834\u5408\u306f\u3001\u524d\u306e\u65b9\u3067\u3067\u6319\u3052\u305f\u3088\u3046\u306a\u3001orElse \u3067\u89aa\u8981\u7d20\u3082\u30c1\u30a7\u30c3\u30af\u3059\u308b\u65b9\u6cd5\u3067\u4e57\u308a\u5207\u308c\u308b\u3063\u307d\u3044\u3002<\/p>\n<p>\u3082\u3063\u3068\u7dba\u9e97\u306a\u65b9\u6cd5\u306f\u306a\u3044\u3082\u306e\u304b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b Play! framework \u306e JSON \u30e9\u30a4\u30d6\u30e9\u30ea\u3063\u3066\u3001\u6163\u308c\u308c\u3070\u307e\u3041\u666e\u901a\u306b\u4f7f\u3048\u308b\u3051\u3069\u3001\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u304c\u30a4\u30de\u30a4\u30c1\u3060\u3057\u3001\u3084\u308a\u305f\u3044\u3053\u3068\u3092\u3069\u3046\u66f8\u3051\u3070\u3044\u3044\u304b\u304c\u5206\u304b\u3089\u306a\u304f\u3066\u6642\u9593\u3092\u4f7f\u3046\u3053\u3068\u304c\u591a\u3044\u3002 \u4eca\u56de\u66f8\u304f\u306e\u306f\u3001JSON&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[20],"tags":[916,947],"class_list":["post-1520","post","type-post","status-publish","format-standard","hentry","category-scala","tag-play-framework","tag-scala"],"_links":{"self":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/comments?post=1520"}],"version-history":[{"count":2,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1520\/revisions"}],"predecessor-version":[{"id":1522,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1520\/revisions\/1522"}],"wp:attachment":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/media?parent=1520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/categories?post=1520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/tags?post=1520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}