Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

marshalValue silently fails for unsupported values #3

Open
dolmen opened this issue Jun 4, 2019 · 4 comments
Open

marshalValue silently fails for unsupported values #3

dolmen opened this issue Jun 4, 2019 · 4 comments

Comments

@dolmen
Copy link

dolmen commented Jun 4, 2019

marshalValue doesn't handle the wide range of values supported by encoding/json (such as any value implementing json.Marshaler) but silently fails (no output) instead of reporting an error indicating an unsupported data type.

Example: https://play.golang.org/p/dmF0aGDl0J5

package main

import (
	"encoding/json"
	"fmt"
	"log"

	"github.com/TylerBrock/colorjson"
)

func main() {
	raw := json.RawMessage(`{
  "str": "foo",
  "num": 100,
  "bool": false,
  "null": null,
  "array": ["foo", "bar", "baz"],
  "obj": { "a": 1, "b": 2 }
}`)

	f := colorjson.NewFormatter()
	f.Indent = 2

	b, err := f.Marshal(raw)
	if err != nil {
		log.Fatal(err)
	}
	if len(b) == 0 {
		log.Fatal("no output")
	}
	fmt.Println(string(b))
}
@dolmen dolmen changed the title marshalValue silently fails marshalValue silently fails for unsupported values Jun 4, 2019
@diogogmt
Copy link

Came across the same issue.
When calling colorjson.Marshal no error and no output is returned back.

@pablodz
Copy link

pablodz commented Oct 15, 2021

bump

@DaveGardner-Alfi
Copy link

same

1 similar comment
@Freccia
Copy link

Freccia commented Oct 12, 2022

same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants