#445·go

TimeNotBuiltin fails to decode legacy MessagePack times in v1.3.x

Author: ionutboangiuCreated Sep 24, 2026Updated Sep 27, 2026

With TimeNotBuiltin = true, v1.3.x fails to decode time.Time fields written by v1.2.14. After upgrading, we can no longer read our existing data.

go
package main

import (
	"fmt"
	"os"
	"time"

	"github.com/ugorji/go/codec"
)

type Data struct {
	T time.Time
}

func main() {
	h := new(codec.MsgpackHandle)
	h.TimeNotBuiltin = true

	// Encoded with v1.2.14 using the same handle settings. T is 2026-01-01 00:00:00 UTC.
	data := []byte{
		0x81, 0xa1, 0x54, 0xaf, 0x01, 0x00, 0x00, 0x00, 0x0e, 0xe0,
		0xe7, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
	}
	var v Data
	if err := codec.NewDecoderBytes(data, h).Decode(&v); err != nil {
		fmt.Println("decode failed:", err)
		os.Exit(1)
	}
	fmt.Println("decoded:", v.T)
}

v1.2.14:

decoded: 2026-01-01 00:00:00 +0000 UTC

v1.3.2:

decode failed: msgpack decode error [pos 4]: invalid length of bytes for decoding time - expecting 4 or 8 or 12, got 15

Is this change intentional, or should TimeNotBuiltin still support the legacy encoding discussed in https://github.com/ugorji/go/issues/269?