compatibility.go 1.0 KB

123456789101112131415161718192021222324252627282930
  1. package bson
  2. // Current state of the JSON tag fallback option.
  3. var useJSONTagFallback = false
  4. var useRespectNilValues = false
  5. // SetJSONTagFallback enables or disables the JSON-tag fallback for structure tagging. When this is enabled, structures
  6. // without BSON tags on a field will fall-back to using the JSON tag (if present).
  7. func SetJSONTagFallback(state bool) {
  8. useJSONTagFallback = state
  9. }
  10. // JSONTagFallbackState returns the current status of the JSON tag fallback compatability option. See SetJSONTagFallback
  11. // for more information.
  12. func JSONTagFallbackState() bool {
  13. return useJSONTagFallback
  14. }
  15. // SetRespectNilValues enables or disables serializing nil slices or maps to `null` values.
  16. // In other words it enables `encoding/json` compatible behaviour.
  17. func SetRespectNilValues(state bool) {
  18. useRespectNilValues = state
  19. }
  20. // RespectNilValuesState returns the current status of the JSON nil slices and maps fallback compatibility option.
  21. // See SetRespectNilValues for more information.
  22. func RespectNilValuesState() bool {
  23. return useRespectNilValues
  24. }