Serge Bazanski | cc25bdf | 2018-10-25 14:02:58 +0200 | [diff] [blame] | 1 | package bson |
| 2 | |
| 3 | // Current state of the JSON tag fallback option. |
| 4 | var useJSONTagFallback = false |
| 5 | var 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). |
| 9 | func 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. |
| 15 | func 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. |
| 21 | func 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. |
| 27 | func RespectNilValuesState() bool { |
| 28 | return useRespectNilValues |
| 29 | } |