Unsupported UString Type Using Aeson with MongoDB BSON

I am trying to use Data.Aeson.TH getiveJSON to instantiate ToJSON and FromJSON for MongoDB Data.Bson.

I am currently using:

$(deriveJSON id ''Data.Bson.Field) $(deriveJSON id ''Data.Bson.Value) $(deriveJSON id ''Data.Bson.Binary) $(deriveJSON id ''Data.Bson.UUID) $(deriveJSON id ''Data.Bson.UserDefined) $(deriveJSON id ''Data.Bson.Regex) $(deriveJSON id ''Data.Bson.Symbol) $(deriveJSON id ''Data.Bson.MinMaxKey) $(deriveJSON id ''Data.Bson.MongoStamp) $(deriveJSON id ''Data.Bson.Javascript) $(deriveJSON id ''Data.Bson.ObjectId) $(deriveJSON id ''Data.Bson.MD5) $(deriveJSON id ''Data.Bson.Function) $(deriveJSON id ''Data.Bson.UString) 

Which generates the following error at compile time:

 Exception when trying to run compile-time code: Data.Aeson.TH.withType: Unsupported type: TySynD Data.UString.UString [] (ConT Data.CompactString.UTF8.CompactString) Code: deriveJSON (id) 'UString 

I think the problem here is that the line inside the BSON document is Ustring. I need to convert or otherwise display the expected UString in the BSON data to another type of String ... but a dead end as to how.

+4
source share
1 answer

As I said, Aeson does not support type synonyms, but nothing prevents us from deploying UString.

 type UString = Data.CompactString.CompactString type CompactString = Data.CompactString.Internal.CompactString UTF8 

So this one (instead of output for UString ) will work:

 $(deriveJSON id ''Data.CompactString.Internal.CompactString) $(deriveJSON id ''Data.CompactString.Encodings.UTF8) 
+2
source

Source: https://habr.com/ru/post/1387304/


All Articles