douguanyun2169 2015-06-26 13:25
浏览 282
已采纳

Golang编码/ json Marshaler

As stated in the encoding/json package documentation,

Marshal traverses the value v recursively. If an encountered value implements the Marshaler interface and is not a nil pointer, Marshal calls its MarshalJSON method to produce JSON.

Where exactly in the code is this test performed?

In another terms, how does encoding/json check if a value v of type t implements the Marshaller interface?

  • 写回答

1条回答 默认 最新

  • download92000 2015-06-26 13:31
    关注

    Here :

    Golang encoding/json Marshaler

    if t.Implements(marshalerType) {
        return marshalerEncoder
    }
    

    Edit: The link above has been updated to point to a specific version of Go, as @dave-c pointed out in comments below.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?