Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Bug: Cannot Unmarshal null fields to UUID #689

Open

Description

@farisekananda

Cannot unmarshal null fields to UUID, even though I already uses ConfigCompatibleWithStandardLibrary which ensures 100% compatibility.

It also fails with the NewDecoder.Decode function.

Sample Program:

package main

import (
	"bytes"
	"fmt"

	"encoding/json"

	"github.com/google/uuid"
	jsoniterlib "github.com/json-iterator/go"
)

type TestStruct struct {
	SomeUUID uuid.UUID `json:"someUUID"`
	NilUUID  uuid.UUID `json:"nilUUID"`
}

var jsoniter = jsoniterlib.ConfigCompatibleWithStandardLibrary

func main() {
	fmt.Println("jsoniter fails to decode null field to UUID")
	var err error
	var test TestStruct
	err = jsoniter.Unmarshal(bytes.NewBufferString(`{"someUUID":"fa0e715a-7234-4110-aed0-ecc3de305e62","nilUUID":null}`).Bytes(), &test)
	fmt.Println(test)
	fmt.Println(err)

	fmt.Println("\nexpected results:")
	var err2 error
	var test2 TestStruct
	err2 = json.Unmarshal(bytes.NewBufferString(`{"someUUID":"fa0e715a-7234-4110-aed0-ecc3de305e62","nilUUID":null}`).Bytes(), &test2)
	fmt.Println(test2)
	fmt.Println(err2)
}

Results:

jsoniter fails to decode null field to UUID
{fa0e715a-7234-4110-aed0-ecc3de305e62 00000000-0000-0000-0000-000000000000}
main.TestStruct.NilUUID: textUnmarshalerDecoder: invalid UUID length: 0, error found in #10 byte of ...|UUID":null}|..., bigger context ...|0e715a-7234-4110-aed0-ecc3de305e62","nilUUID":null}|...

expected results:
{fa0e715a-7234-4110-aed0-ecc3de305e62 00000000-0000-0000-0000-000000000000}
<nil>

Ran on golang 1.21.0

Activity

  1. gallone2000 commented on Jun 18, 2024

    @gallone2000

    @farisekananda I made some checks in my local einvironment (go 1.20.14) with the latest version available for this pkg and no errors have been raised

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions