【问题标题】:Get the underlying HList out from Circe从 Circe 获取底层 HList
【发布时间】:2018-04-08 04:38:15
【问题描述】:

是否可以从circe 而不是 JSON 中获取底层 hlist 表示?本质上将案例类转换为 HList

注意:我知道这可以直接使用 shapeless 实现,我想尝试基于 circe's 宏的解析器,因为我遇到了 shapeless 的性能问题。

【问题讨论】:

    标签: scala shapeless circe


    【解决方案1】:

    您为什么认为有任何“来自circe 的基础 hlist 表示”?

    circe 所做的是将parsingString 引入JSON,引入类型类DecoderEncoder

    trait Encoder[A] extends Serializable { self =>
      def apply(a: A): Json
    //...
    }
    
    trait Decoder[A] extends Serializable { self =>
      def apply(c: HCursor): Decoder.Result[A]
    //...
    }
    

    deriving 这些类型类使用shapeless。例如,这意味着如果我们有Decoder[H]Decoder[T],那么我们就有Decoder[H :: T]。但是对于 Json 以外的案例类,没有底层的 circe 表示形式。

    circe 不会将 case 类转换为 HListshapeless 会。

    【讨论】:

    • 好的,谢谢。我认为它会使用 hlist 作为中间表示。
    猜你喜欢
    • 2013-05-09
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多