-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
I've managed to get it via generics-sop, but I don't have much experience in this stuff.
data T a = T
{ field_reps :: Int
, field_what :: Text
, field_ignore :: Char
, field_inside :: a
}
deriving (Show, Eq)
deriveGeneric ''T -- SOP
-- relies on unjsonDef for all fields
unjT :: (Typeable a, Unjson a) => UnjsonDef (T a)
unjT = gunjson
do T.stripPrefix "field_"
do [ "number of repetitions"
, "string to repeat"
, "char to ignore"
, "inside the T"
]
do T
-- specify unjsonDef per field
unjUT :: (Typeable a, Unjson a) => UnjsonDef (T a)
unjUT = gunjsonU
do T.stripPrefix "field_"
do C "number of repetitions" unjsonDef
:* C "string to repeat"
do invmap T.reverse T.reverse unjsonDef
:* C "char to ignore" unjsonDef
:* C "inside the T" unjsonDef
:* Nil
do T
instance (Typeable a, Unjson a) => Unjson (T a)
where unjsonDef = unjUT
testV = T 54 "mamma" 'a' (T 32 "piero" 'p' (128 :: Int))
roundTest :: forall a. (Unjson a, Eq a) => a -> Bool
roundTest x = (parse unjsonDef . traceShowId . unjsonToJSON unjsonDef) x == Result x []
If you think it can be good to have, I can file a MR
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels