Skip to content
Myr

json.go

This file

Path

codec/json/json.go

41 lines · 919 bytes · Go

Last changed by

feat: support custom json codec at runtime (#3391)Timbefore adoption688a429

History of this file

Take it

1// Copyright 2025 Gin Core Team. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45//go:build !jsoniter && !go_json && !(sonic && (linux || windows || darwin))67package json89import (10	"encoding/json"11	"io"12)1314// Package indicates what library is being used for JSON encoding.15const Package = "encoding/json"1617func init() {18	API = jsonApi{}19}2021type jsonApi struct{}2223func (j jsonApi) Marshal(v any) ([]byte, error) {24	return json.Marshal(v)25}2627func (j jsonApi) Unmarshal(data []byte, v any) error {28	return json.Unmarshal(data, v)29}3031func (j jsonApi) MarshalIndent(v any, prefix, indent string) ([]byte, error) {32	return json.MarshalIndent(v, prefix, indent)33}3435func (j jsonApi) NewEncoder(writer io.Writer) Encoder {36	return json.NewEncoder(writer)37}3839func (j jsonApi) NewDecoder(reader io.Reader) Decoder {40	return json.NewDecoder(reader)41}