YAPC::EU 2018 Glasgow Update!

This commit is contained in:
Ingy döt Net 2018-08-17 15:15:24 +01:00
parent 22f33d4004
commit 4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions

View file

@ -0,0 +1,14 @@
require "json"
class Foo
JSON.mapping(
num: Int64,
array: Array(String),
)
end
def json
foo = Foo.from_json(%({"num": 1, "array": ["a", "b"]}))
puts("#{foo.num} #{foo.array}")
puts(foo.to_json)
end

View file

@ -0,0 +1,2 @@
1 ["a", "b"]
{"num":1,"array":["a","b"]}

View file

@ -0,0 +1,17 @@
{-# LANGUAGE DeriveGeneric, OverloadedStrings #-}
import Data.Aeson
import GHC.Generics
data Person = Person { firstName :: String
, lastName :: String
, age :: Maybe Int
} deriving (Show, Eq, Generic)
instance FromJSON Person
instance ToJSON Person
main = do
let test1 = "{\"firstName\":\"Bob\", \"lastName\":\"Smith\"}"
test2 = "{\"firstName\":\"Miles\", \"lastName\":\"Davis\", \"age\": 45}"
print (decode test1 :: Maybe Person)
print (decode test2 :: Maybe Person)