JSONUtility.toModel(): add support for parsing maps #1350
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.
Since #1312 was merged, I wanted to try using it as part of my project to get Java debugging working with vim-lsp and java-debug. Unfortunately, my first attempt at using the API failed because the language server doesn't know how to handle map-type arguments natively.
For context, here is how I'm invoking the new API:
Initially, this resulted in a
NullPointerException
being raised here becauseoptions
is null.I tracked the error down to
JSONUtility.toModel()
returning null for theclasspathOptions
argument, and from there determined that it was actually an instance ofcom.google.gson.internal.LinkedTreeMap
, causingtoModel()
to return null because it didn't match any of the expected types.For simple cases such as this one, I think it would make sense for
JSONUtility.toModel()
to be smart enough to map the fields of a map into a model object, so that users of the API don't have to manually encode dictionaries into a JSON object.