Code Explainers

Code explainers tagged #serialization

typescript
type CsvColumn<T> = {
  header: string;
  value: (row: T) => string | number | boolean | null | undefined;
};

Building a type-safe CSV writer in TypeScript

generics serialization escaping
Intermediate 7 steps
ruby
require "base64"
require "json"
 
module Attachment

Packing binary attachments into JSON

serialization base64 json
Intermediate 8 steps
typescript
import { Exclude, Expose, Transform, Type } from 'class-transformer';
 
export class AddressEntity {
  street: string;

Shaping API responses with class-transformer in NestJS

serialization decorators dto
Intermediate 10 steps
python
from flask import Blueprint, render_template, jsonify, request, abort
 
from .models import Article
 

Content negotiation in a Flask Blueprint

content-negotiation http-headers routing
Intermediate 7 steps
rust
use axum::{
    http::{header, StatusCode},
    response::{IntoResponse, Response},
    Json,

Turning errors into RFC 7807 responses in Axum

error-handling enums trait-implementation
Intermediate 7 steps
rust
use serde::{Deserialize, Serialize};
 
#[derive(Debug, Serialize, Deserialize)]
pub struct UserProfile {

Trimming JSON output with serde attributes

serialization json attributes
Intermediate 8 steps
rust
use axum::{
    body::Body,
    extract::State,
    http::{header, StatusCode},

Streaming NDJSON from Postgres in Axum

streaming backpressure async
Advanced 9 steps
ruby
require "csv"
 
class CsvExporter
  def initialize(records, columns: nil)

Turning records into CSV in Ruby

csv data-export serialization
Intermediate 7 steps
ruby
require "openssl"
require "json"
require "base64"
 

Building signed session tokens in Ruby

hmac authentication cryptography
Intermediate 8 steps
rust
use axum::{
    extract::Path,
    http::StatusCode,
    routing::{get, post},

Building a REST resource in Axum

rest-api routing serialization
Intermediate 9 steps
python
from flask import Blueprint, request, url_for, jsonify, abort
from flask.views import MethodView
 
from .models import Article, db

Building a paginated JSON API with Flask MethodView

rest-api pagination class-based-views
Intermediate 10 steps
java
public final class DeepCopier {
 
    private static final ObjectMapper MAPPER = new ObjectMapper()
            .registerModule(new JavaTimeModule())

Deep-copying objects via Jackson serialization

serialization deep-copy generics
Intermediate 7 steps
go
package render
 
import (
	"net/http"

How Gin renders MsgPack responses

serialization content-type interface-implementation
Intermediate 5 steps
go
package tsvio
 
import (
	"bufio"

Reading and writing TSV records in Go

parsing io-streams error-handling
Intermediate 10 steps
python
from flask import Blueprint, jsonify, request, abort
 
v1 = Blueprint("users_v1", __name__)
v2 = Blueprint("users_v2", __name__)

Versioning a Flask API with Blueprints

api versioning blueprints rest
Intermediate 7 steps
go
package deepcopy
 
import (
	"bytes"

Deep copying any value with gob in Go

deep-copy serialization generics
Intermediate 6 steps
java
@Component
required to import
public class OutboxEventPublisher {
 

The transactional outbox pattern in Spring

transactional-outbox event-driven reliability
Advanced 7 steps
php
<?php
 
namespace App\Http\Resources;
 

Shaping API JSON with a Laravel Resource

api serialization data transformation
Intermediate 7 steps