-
Notifications
You must be signed in to change notification settings - Fork 914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for JSON #3007
Merged
Merged
Support for JSON #3007
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
akutz
force-pushed
the
feature/json-support
branch
16 times, most recently
from
December 13, 2022 16:00
49d7971
to
2e7fa94
Compare
This patch vendors the sources from Go 1.17.13's encoding/json package in the package vim25/json.
akutz
force-pushed
the
feature/json-support
branch
5 times, most recently
from
December 15, 2022 04:03
3d75698
to
a3d5553
Compare
This patch introduces support for discriminators to the "encoding/json" package. A discriminator is a field in a JSON object that indicates the object's type. For example: { "breed": "Lab" } The above JSON does not indicate the Go type into which the object should be decoded. However, it is possible to store that Go type information along with the JSON: { "_typeName": "Dog", "breed": "Lab" } The "_typeName" field teaches the JSON decoder to unmarshal the object into the Go type named "Dog". This patch introduces functions for the json.Encoder and json.Decoder that may be used to active support for discriminators.
This patch adds Go's LICENSE file to the vendored JSON package.
This patch adds a README to the vendored JSON package describing its purpose and how to show the diff between the original sources and the patch applied to the vendored copy.
This patch excludes the vendored vim25/json package from the GitHub action that checks code style for Go sources.
akutz
force-pushed
the
feature/json-support
branch
3 times, most recently
from
December 15, 2022 06:44
b1e2692
to
b7c16c1
Compare
dougm
reviewed
Dec 15, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This patch updates the type generation code to support adding JSON tags to generated type field data. BREAKING: Updating the `vim25/types` with camelCased, JSON tags affects the output of the `govc` command when using the `-json` flag to emit results as JSON. Field names that used to be PascalCased will now be camelCased. Queries for tools that parse JSON, such as `jq`, will need to be updated to use the new camelCased fields.
This patch adds support to GoVmomi for marshaling/unmarshaling the vim25/types (and other VMODL1 types) to/from JSON using: * a customized version of the Golang encoding/json package that relies upon... * a new discriminator field added to every every complex object marshaled to JSON, the "_typeName" field. this field's value must match the value of the type's registered type name from the type registry
akutz
force-pushed
the
feature/json-support
branch
from
December 15, 2022 17:42
b7c16c1
to
4e6d642
Compare
dougm
approved these changes
Dec 15, 2022
dougm
added a commit
to dougm/govmomi
that referenced
this pull request
Sep 25, 2023
dougm
added a commit
to dougm/govmomi
that referenced
this pull request
Sep 25, 2023
dougm
added a commit
that referenced
this pull request
Sep 27, 2023
dougm
added a commit
that referenced
this pull request
Sep 27, 2023
dougm
added a commit
to dougm/govmomi
that referenced
this pull request
Sep 27, 2023
PR vmware#3007 added camelCase json tags for generated types BREAKING: This change adds camelCase (lower-case 1st character) json tags for govc types Fixes vmware#3243 Fixes vmware#3242 Fixes vmware#3241
dougm
added a commit
to dougm/govmomi
that referenced
this pull request
Sep 27, 2023
PR vmware#3007 added camelCase json tags for generated types BREAKING: This change adds camelCase (lower-case 1st character) json tags for govc types Fixes vmware#3243 Fixes vmware#3242 Fixes vmware#3241
dougm
added a commit
to dougm/govmomi
that referenced
this pull request
Sep 27, 2023
PR vmware#3007 added camelCase json tags for generated types BREAKING: This change adds camelCase (lower-case 1st character) json tags for govc types Fixes vmware#3243 Fixes vmware#3242 Fixes vmware#3241
priyanka19-98
pushed a commit
to priyanka19-98/govmomi
that referenced
this pull request
Jan 17, 2024
priyanka19-98
pushed a commit
to priyanka19-98/govmomi
that referenced
this pull request
Jan 17, 2024
priyanka19-98
pushed a commit
to priyanka19-98/govmomi
that referenced
this pull request
Jan 17, 2024
PR vmware#3007 added camelCase json tags for generated types BREAKING: This change adds camelCase (lower-case 1st character) json tags for govc types Fixes vmware#3243 Fixes vmware#3242 Fixes vmware#3241
dougm
added a commit
to dougm/govmomi
that referenced
this pull request
Feb 8, 2024
BREAKING: follow up to json tags missed in PR vmware#3007 and PR vmware#3247 Closes vmware#3318
This was referenced Feb 12, 2024
dougm
added a commit
to dougm/govmomi
that referenced
this pull request
Dec 24, 2024
PR vmware#3007 added camelCase json tags for generated types PR vmware#3247 added camelCase json tags for govc commands This change does the same for cns/types. Signed-off-by: Doug MacEachern <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This patch adds support to GoVmomi for marshaling/unmarshaling the
vim25/types
(and other VMODL1 types) to/from JSON using:encoding/json
package that relies upon_typeName
field. this field's value must match the value of the type's registered type name from the type registryAdditionally, in order to avoid creating a bespoke JSON codec package, it was necessary to essentially vendor the Golang
encoding/json
package and modify it to support this feature. However, changes were kept to a minimum, with discriminator support an explicit choice enabled on instances ofEncoder
andDecoder
.The diff between the vendored package and the source from Go 1.17.13 further serves to highlight how minimal the changes are:
This is also a breaking change in that certain output from
govc -json
will now produce field names that are camelCase instead of PascalCase.Closes:
NA
Type of change
Please mark options that are relevant:
not work as expected)
How Has This Been Tested?
$ go test -race -v -run JSON ./vim25/types === RUN TestJSONMarshalVirtualMachineConfigSpec --- PASS: TestJSONMarshalVirtualMachineConfigSpec (0.00s) === RUN TestJSONUnmarshalVirtualMachineConfigSpec --- PASS: TestJSONUnmarshalVirtualMachineConfigSpec (0.00s) === RUN TestJSONUnmarshalVirtualMachineConfigInfo --- PASS: TestJSONUnmarshalVirtualMachineConfigInfo (0.01s) PASS ok github.com/vmware/govmomi/vim25/types 0.194s
Checklist:
CONTRIBUTION
guidelines of this project