mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-10-23 13:02:28 +00:00
update aeson to add tag to platform-specific single field JSON encoding (#859)
* update aeson to add tag to platform-specific single field JSON encoding * refactor
This commit is contained in:
1 parent
96a38505d6
commit
9195509485
3 files changed
+13
-5
No files matched your search
@@ -107,13 +107,17 @@ enumJSON tagModifier =
|
||||
J.allNullaryToStringTag = True
|
||||
}
|
||||
|
||||
-- used in platform-specific encoding, includes tag for single-field encoding of sum types to allow conversion to tagged objects
|
||||
sumTypeJSON :: (String -> String) -> J.Options
|
||||
#if defined(darwin_HOST_OS) && defined(swiftJSON)
|
||||
sumTypeJSON = singleFieldJSON
|
||||
sumTypeJSON = singleFieldJSON_ $ Just singleFieldJSONTag
|
||||
#else
|
||||
sumTypeJSON = taggedObjectJSON
|
||||
#endif
|
||||
|
||||
singleFieldJSONTag :: String
|
||||
singleFieldJSONTag = "_owsf"
|
||||
|
||||
taggedObjectJSON :: (String -> String) -> J.Options
|
||||
taggedObjectJSON tagModifier =
|
||||
J.defaultOptions
|
||||
@@ -125,10 +129,14 @@ taggedObjectJSON tagModifier =
|
||||
J.omitNothingFields = True
|
||||
}
|
||||
|
||||
-- used in platform independent encoding, doesn't include tag for single-field encoding of sum types
|
||||
singleFieldJSON :: (String -> String) -> J.Options
|
||||
singleFieldJSON tagModifier =
|
||||
singleFieldJSON = singleFieldJSON_ Nothing
|
||||
|
||||
singleFieldJSON_ :: Maybe String -> (String -> String) -> J.Options
|
||||
singleFieldJSON_ objectTag tagModifier =
|
||||
J.defaultOptions
|
||||
{ J.sumEncoding = J.ObjectWithSingleField,
|
||||
{ J.sumEncoding = J.ObjectWithSingleField objectTag,
|
||||
J.tagSingleConstructors = True,
|
||||
J.constructorTagModifier = tagModifier,
|
||||
J.allNullaryToStringTag = False,
|
||||
|
||||
Reference in new issue
Block a user