Properly encode dictionnaries with string index

This commit is contained in:
Simon Marechal 2020-05-21 09:03:43 +02:00
parent 0856922e8c
commit a18ab729e8
2 changed files with 2 additions and 1 deletions

View File

@ -177,6 +177,7 @@ jsonSerForType' omitnull ty =
then jsonSerForType t'
else "(maybeEncode (" ++ jsonSerForType t' ++ "))"
ETyApp (ETyCon (ETCon "Set")) t' -> "(encodeSet " ++ jsonSerForType t' ++ ")"
ETyApp (ETyApp (ETyCon (ETCon "Dict")) (ETyCon (ETCon "String"))) value -> "(Json.Encode.dict identity (" ++ jsonSerForType value ++ "))"
ETyApp (ETyApp (ETyCon (ETCon "Dict")) key) value -> "(encodeMap (" ++ jsonSerForType key ++ ") (" ++ jsonSerForType value ++ "))"
_ ->
case unpackTupleType ty of

View File

@ -64,7 +64,7 @@ moduleCode elmVersion = unlines
, " , (\"blablub\", Json.Encode.int val.blablub)"
, " , (\"tuple\", (\\(t1,t2) -> Json.Encode.list identity [(Json.Encode.int) t1,(Json.Encode.string) t2]) val.tuple)"
, " , (\"list\", (Json.Encode.list Json.Encode.bool) val.list)"
, " , (\"list_map\", (Json.Encode.list (encodeMap (Json.Encode.string) (Json.Encode.bool))) val.list_map)"
, " , (\"list_map\", (Json.Encode.list (Json.Encode.dict identity (Json.Encode.bool))) val.list_map)"
, " ]"
, ""
]