diff options
author | 2018-07-25 13:58:02 -0700 | |
---|---|---|
committer | 2018-07-25 13:59:42 -0700 | |
commit | 7fe7047e6e6aec82f78cca366f0604dd606a5e7e (patch) | |
tree | 72b158530314b509a9637ba33af1dfa124085e19 /src/main/java/com/google/devtools/build/lib/skylarkbuildapi | |
parent | 59a0b3f7c9d69b7be3be23ee57a8c058130ac9e8 (diff) |
[Skylark] Support dictionaries in structs when serializing them using struct.to_json.
Dictionaries are frequently used for generic configuration descriptions especially
given that `struct` is not allowed in build files.
In order to be JSON-compatible, only dictionaries with string keys are allowed.
Technically Python also allows integers and booleans by automatically converting
them to strings, but this is confusing and not necessarily a good thing to do.
Fixes #5542
Closes #5543.
PiperOrigin-RevId: 206049754
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skylarkbuildapi')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skylarkbuildapi/StructApi.java | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/StructApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/StructApi.java index 5c0974975c..49d90e5ac7 100644 --- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/StructApi.java +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/StructApi.java @@ -60,8 +60,9 @@ public interface StructApi extends SkylarkValue { name = "to_json", doc = "Creates a JSON string from the struct parameter. This method only works if all " - + "struct elements (recursively) are strings, ints, booleans, other structs or a " - + "list of these types. Quotes and new lines in strings are escaped. " + + "struct elements (recursively) are strings, ints, booleans, other structs, a " + + "list of these types or a dictionary with string keys and values of these types. " + + "Quotes and new lines in strings are escaped. " + "Examples:<br><pre class=language-python>" + "struct(key=123).to_json()\n# {\"key\":123}\n\n" + "struct(key=True).to_json()\n# {\"key\":true}\n\n" |