, c :: Int <?> "d", e :: Maybe Int <?> "f" }
deriving stock (Generic, Show)
deriving (FromJSON, ToJSON) via CustomJSON '[OmitNothingFields] (ViaNamed X)
main :: IO ()
main = do
print $ decode @X "{\"b\": 1, \"d\": 2}"
print $ decode @X "{\"b\": 1, \"d\": 2, \"f\": 3}"
print $ encode X{a = N 1, c = N 2, e = N Nothing}
print $ encode X{a = N 1, c = N 2, e = N (Just 3)}
Just (X {a = N 1, c = N 2, e = N Nothing})
Just (X {a = N 1, c = N 2, e = N (Just 3)})
"{\"b\":1,\"d\":2}"
"{\"b\":1,\"d\":2,\"f\":3}"
?
Так, я заинтересован
Обсуждают сегодня