4

MongoDB Data.Bson の ToJSON および FromJSON インスタンスを生成するために Data.Aeson.TH serveJSON を使用しようとしています。

現時点で私は使用しています:

$(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)

コンパイル時に次のエラーが生成されます。

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

ここでの問題は、BSON ドキュメント内の文字列が Ustring であることだと思います。BSON データ内で期待される UString を別の String 型に変換するか、別の方法でマップする必要がありますが、方法については困惑しています。

4

1 に答える 1

2

前述したように、Aeson は型シノニムをサポートしていませんが、UString の展開を妨げるものは何もありません。

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

したがって、これは ( の代わりにUString) 機能します。

$(deriveJSON id ''Data.CompactString.Internal.CompactString)
$(deriveJSON id ''Data.CompactString.Encodings.UTF8)
于 2011-12-21T20:37:52.153 に答える