Upgrade to Pro — share decks privately, control downloads, hide ads and more …

サーバサイドKotlinのすすめ

noripi
August 05, 2017

 サーバサイドKotlinのすすめ

2017.08.05 buildersconで使用したスライドです。

noripi

August 05, 2017
Tweet

More Decks by noripi

Other Decks in Technology

Transcript

  1. ޾ͤʹͳΕͦ͏ͳ,PUMJOͷػೳ  interface IRestaurantInfo { @JsonProperty(“restaurant_id”) val restaurantId: Long @JsonProperty(“restaurant_name”)

    val restaurantName: String } ɾEBUBDMBTT ɾ୯ʹσʔλߏ଄͚ͩΛද͢Ϋϥεʢ$ݴޠ΍4XJGUͰ͍͏ߏ଄ମʣΛ
 ɹγϯϓϧʹදݱͰ͖Δ ɾΠϯλϑΣʔεΛ࣮૷͢Δ͜ͱ΋Ͱ͖ΔͷͰදهΏΕͷܰݮʹ໾ཱͭ data class Restaurant(override val restaurantId: Long, 
 override val restaurantName: String, val station: Station?): IRestaurantInfo
  2. ޾ͤʹͳΕͦ͏ͳ,PUMJOͷػೳ  ɾJGXIFOUSZ͸ࣜ ɾͭ·ΓฦΓ஋Λ͍࣋ͬͯΔ Restaurant jsonObj; try { jsonObj =

    ObjectMapper().readValue(result, Restaurant.class); } catch (JsonProcessingException e) { jsonObj = RestaurantModel.get(id); } val jsonObj: Restaurant = try { ObjectMapper().readValue(result, Restaurant::class.java) } catch (e: JsonProcessingException) { RestaurantModel.get(id) }
  3. ޾ͤʹͳΕͦ͏ͳ,PUMJOͷػೳ  ɾ֦ுؔ਺ ɾطଘͷΫϥεʹࣗ෼ͷ޷͖ͳϝιουΛ଍͢͜ͱ͕Ͱ͖Δ fun <K, V> Map<K, V>.toQueryString(): String

    { return this.keys.map { key -> this[key]?.let { “$key=${this[key]}" } }.filterNotNull().joinToString("&") } // a=1&b=2 val queryStr = mapOf("a" to 1, "b" to 2).toQueryString()