2011-12-21 11 views
4

MongoDB Data.BsonのToJSONインスタンスとFromJSONインスタンスを生成するためにData.Aeson.TH deriveJSONを使用しようとしています。現時点でサポートされていない型MongoDBでAesonを使用するUString BSON

私が使用しています:コンパイル時に次のエラーが発生し

$(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型に変換するか、別の方法でマップする必要がありますが、どうやってどうしたらよいか分かりません。

+0

を[アイソーンソース](HTTP(アイソーンが型シノニムをサポートしていないようです。 org/packages/archive/aeson/0.4.0.0/doc/html/src/Data-Aeson-TH.html#withType))。しかし、 'UString'は型の同義語です([bson doc](http://hackage.haskell.org/packages/archive/bson/0.1.6/doc/html/Data-UString.html))。 'TySynD'の場合を' withType'に追加すると助けになるかもしれませんが、わかりません。 –

+0

あなたは[aesonBson](http://hackage.haskell.org/package/AesonBson)に興味があるかもしれません。 – nh2

答えて

2

私が言及したように、Aesonは型同義語をサポートしていませんが、UStringの展開を妨げるものはありません。だから、

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

、これは(代わりのUStringのために導出)に動作します://hackage.haskell:

$(deriveJSON id ''Data.CompactString.Internal.CompactString) 
$(deriveJSON id ''Data.CompactString.Encodings.UTF8) 
関連する問題