Skip to content
Myr

jsoniter.go

This file

Path

codec/json/jsoniter.go

44 lines · 985 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 jsoniter67package json89import (10	"io"1112	jsoniter "github.com/json-iterator/go"13)1415// Package indicates what library is being used for JSON encoding.16const Package = "github.com/json-iterator/go"1718func init() {19	API = jsoniterApi{}20}2122var json = jsoniter.ConfigCompatibleWithStandardLibrary2324type jsoniterApi struct{}2526func (j jsoniterApi) Marshal(v any) ([]byte, error) {27	return json.Marshal(v)28}2930func (j jsoniterApi) Unmarshal(data []byte, v any) error {31	return json.Unmarshal(data, v)32}3334func (j jsoniterApi) MarshalIndent(v any, prefix, indent string) ([]byte, error) {35	return json.MarshalIndent(v, prefix, indent)36}3738func (j jsoniterApi) NewEncoder(writer io.Writer) Encoder {39	return json.NewEncoder(writer)40}4142func (j jsoniterApi) NewDecoder(reader io.Reader) Decoder {43	return json.NewDecoder(reader)44}