// Copyright 2018 Gin Core Team. All rights reserved. // Use of this source code is governed by a MIT style // license that can be found in the LICENSE file. // +build go1.7 package json import ( "net/http" "github.com/gin-gonic/gin/internal/json" "github.com/gin-gonic/gin/render/common" ) func init() { common.List["PureJSON"] = NewPureJSON } //NewPureJSON build a new PureJSON render func NewPureJSON(obj interface{}, _ map[string]string) common.Render { return PureJSON{Data: obj} } // PureJSON contains the given interface object. type PureJSON struct { Data interface{} } // Render (PureJSON) writes custom ContentType and encodes the given interface object. func (r PureJSON) Render(w http.ResponseWriter) error { r.WriteContentType(w) encoder := json.NewEncoder(w) encoder.SetEscapeHTML(false) return encoder.Encode(r.Data) } // WriteContentType (PureJSON) writes custom ContentType. func (r PureJSON) WriteContentType(w http.ResponseWriter) { common.WriteContentType(w, jsonContentType) }