0

I want to get some ideas to handle a JSON structure like this. Especially for the '/' key.

{
    "tree":{
        "/":"1234567890"
    },
    "parents":null
}

I created this (works if I replace / with slash in the given JSON)

private class Test {
    private SubDirectory tree;
    private String parents;
}

private class SubDirectory {
    private String slash;
    // private String /; obviously not working :D
}

using Gson with a InputStreamReader and then:

Test p = gson.fromJson(reader, Test.class);

So my first idea is to check reader and replace that / to slash. But really ?! ...

Little Helper
  • 1,870
  • 3
  • 12
  • 20
Johannes Knust
  • 891
  • 1
  • 11
  • 18
  • Use a `TreeMap tree` rather than a custom object – OneCricketeer Jul 09 '18 at 14:42
  • @dpr thanks for the link, it helps to go on. I was searching but I missed that map stuff... so I came up with this symbol string to highlight the problem with a custom obj. – Johannes Knust Jul 09 '18 at 15:22
  • @dpr Can you please link it to this stack overflow url? It fits much better. [link]https://stackoverflow.com/questions/30174970/converting-deeply-nested-json-to-java-object-and-vice-versa . The variable type Map solved my problem. – Johannes Knust Jul 10 '18 at 04:38

0 Answers0