repo_description: High performance, minimalist Go web framework
repo_topics: echo go http2 https labstack-echo letsencrypt micro-framework microservice middleware ssl web web-framework websocket
code: // SPDX-License-Identifier: MIT
  // SPDX-FileCopyrightText: © 2015 LabStack LLC and Echo contributors
  
  package echo
  
  import (
  	"encoding/json"
  )
  
  // DefaultJSONSerializer implements JSON encoding using encoding/json.
  type DefaultJSONSerializer struct{}
  
  // Serialize converts an interface into a json and writes it to the response.
  // You can optionally use the indent parameter to produce pretty JSONs.
  func (d DefaultJSONSerializer) Serialize(c *Context, target any, indent string) error {
  	enc := json.NewEncoder(c.Response())
  	if indent != "" {
  		enc.SetIndent("", indent)
  	}
  	return enc.Encode(target)
  }
  
  // Deserialize reads a JSON from a request body and converts it into an interface.
  func (d DefaultJSONSerializer) Deserialize(c *Context, target any) error {
  	if err := json.NewDecoder(c.Request().Body).Decode(target); err != nil {
  		return ErrBadRequest.Wrap(err)
  	}
  	return nil
  }
  