Skip to content

Latest commit

 

History

History
33 lines (18 loc) · 2.37 KB

todos.md

File metadata and controls

33 lines (18 loc) · 2.37 KB
  1. instead of storing objects in cache of pointers, add a brand field to an object to mark as visited

  2. if it's a reflect.Ptr return "ptr (xxxx) -> " + getPrettyString(*deref)

  3. TODO: different log levels for different output files

  4. the command line can set a file descriptor, so reading files in app is not a bad idea

  5. lock section, so that 5 lines of logs can all be in order

In Go, json.Marshal returns an error in a few specific scenarios where the data structure provided to it cannot be serialized into JSON. These scenarios include:

  1. Unsupported Types: Go's json package does not support the serialization of certain types. If you try to marshal channels, functions, or complex numbers, json.Marshal will return an error.

  2. Cyclic References: If the data structure contains cyclic references (i.e., a struct that directly or indirectly references itself), json.Marshal will return an error. JSON cannot represent cyclic data structures.

  3. Invalid UTF-8 Strings: If a string or a slice of bytes contains invalid UTF-8 sequences and is set to be marshaled into a JSON string, json.Marshal may return an error since JSON strings must be valid UTF-8.

  4. Marshaler Errors: If a type implements the json.Marshaler interface and its MarshalJSON method returns an error, json.Marshal will propagate that error.

  5. Pointer to Uninitialized Struct: If you pass a pointer to an uninitialized struct (a nil pointer), json.Marshal will return an error.

  6. Large Floating-Point Values: Extremely large floating-point values (like math.Inf or math.NaN) can cause json.Marshal to return an error, as they do not have a direct representation in JSON.

  7. Unsupported Map Key Types: In Go, a map can have keys of nearly any type, but JSON only supports string keys in objects. If you try to marshal a map with non-string keys (like map[int]string), json.Marshal will return an error.

It's important to note that json.Marshal does not return an error for marshaling private (unexported) struct fields. Instead, it silently ignores them. To include private fields in the JSON output, you either need to export these fields (make their first letter uppercase) or provide a custom marshaling method.

Understanding these conditions can help in ensuring that the data structures used with json.Marshal are compatible with JSON's serialization requirements.