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