2011-12-21 5 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

아이손은 ([아이손 SRC] (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)). 'withType'에'TySynD' 케이스를 추가하면 도움이 될지 모르겠지만 확실하지 않습니다. –

+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) 
관련 문제