krasa / StringManipulation

IntelliJ plugin - https://plugins.jetbrains.com/plugin/2162
Apache License 2.0
694 stars 81 forks source link

Convert Between JSON and YAML action #132

Closed m-radzikowski closed 3 years ago

m-radzikowski commented 3 years ago

A new action "Convert Between JSON and YAML".

I put it under the "Filter/Remove/Trim/Minify" group and added "Convert" to it.

I've used org.json for reading the JSON (simplest) and Gson for writing it (better formatting). Gson and SnakeYAML (used for YAML read/write) are bundled with IntelliJ.

This was my first work with IntelliJ plugin so let me know if there is anything that should be done differently.

Closes #123

krasa commented 3 years ago

Looks good. Only it does not work in this case:

# Employee records
- martin:
    name: Martin D'vloper
    job: Developer
    skills:
      - python
      - perl
      - pascal
- tabitha:
    name: Tabitha Bitumen
    job: Developer
    skills:
      - lisp
      - fortran
      - erlang

java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.util.Map (java.util.ArrayList and java.util.Map are in module java.base of loader 'bootstrap')
    at osmedile.intellij.stringmanip.transform.ConvertJsonYamlAction.yamlToJson(ConvertJsonYamlAction.java:61)
    at osmedile.intellij.stringmanip.transform.ConvertJsonYamlAction.transformSelection(ConvertJsonYamlAction.java:44)
    at osmedile.intellij.stringmanip.AbstractStringManipAction.executeMyWriteActionPerCaret(AbstractStringManipAction.java:91)
    at osmedile.intellij.stringmanip.AbstractStringManipAction$2.perform(AbstractStringManipAction.java:72)
``
m-radzikowski commented 3 years ago

I forgot about arrays 😞

Good you caught it! Should work now.

krasa commented 3 years ago

Nice. Thanks!