Skip to content
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

JSONUtility.toModel(): add support for parsing maps #1350

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dradtke
Copy link

@dradtke dradtke commented Feb 14, 2020

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:

call lsp#send_request('java-language-server', {
      \ 'method': 'workspace/executeCommand',
      \ 'params': {
      \   'command': 'java.project.getClasspaths',
      \   'arguments': [
      \      'file://'.expand('%:p'),
      \      {'scope': 'runtime'},
      \   ],
      \ },
      \ 'sync': v:true,
      \ })

Initially, this resulted in a NullPointerException being raised here because options is null.

I tracked the error down to JSONUtility.toModel() returning null for the classpathOptions argument, and from there determined that it was actually an instance of com.google.gson.internal.LinkedTreeMap, causing toModel() 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.

@eclipse-ls-bot
Copy link

Can one of the admins verify this patch?

@akaroml
Copy link
Contributor

akaroml commented Feb 15, 2020

I would invite @jdneo to take a look since he is the author of #1312

@jdneo
Copy link
Contributor

jdneo commented Feb 16, 2020

This is related with the JDT.LS's fundamental JSON transformations.

BTW, how did you calling the API? I can call it as below:

await extensionApi.getClasspaths(uri, {scope: 'runtime'});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants