In Java best way to convert json string with arrays to flat keys -


i have json file following structure.

    [    {       "type":[          "blog",          "article",          "pressrelease"       ],       "states":[          "scheduled",          "published"       ],       "roles":[          "editor",          "admin"       ],       "actions":[          "review",          "delete"       ]    },    {       "type":[          "blog",          "article",          "pressrelease"       ],       "states":[          "draft",          "review"       ],       "roles":[          "editor",          "admin"       ],       "actions":[          "submit",          "delete"       ]    },    {       "type":[          "blog",          "article"       ],       "states":[          "draft",          "review"       ],       "roles":[          "author"       ],       "actions":[          "submit"       ]    },    {       "type":[          "pressrelease"       ],       "states":[          "draft",          "review"       ],       "roles":[          "pr",          "prm"       ],       "actions":[          "submit"       ]    },    {       "type":[          "pressrelease"       ],       "states":[          "scheduled",          "published"       ],       "roles":[          "prm"       ],       "actions":[          "review",          "delete"       ]    } ] 

i need write method return actions per above json given scenario like.

getactions(type, state, role){ } 

i planning on using gson convert json list of action class objects , build static map key type.state.role , value list of actions processing json few loops. map have

"blog.scheduled.editor" : ["review", "delete"] "blog.scheduled.admin" : ["review", "delete"] "blog.published.editor" : ["review", "delete"] 

.....

"pressrelease.draft.pr" : ["submit"] 

so in getactionas method can return actions creating key input values.

i not sure whether right implementation or there utility job.

you're on right track, suggest using tree instead of map, since it's more natural representation of kind of data.

construct tree this:

* [root] |___ blog |   |___ published |   |   |___ editor |   |   |   |___ review |   |   |   |___ delete |   |   | |   |   |___ admin |   |   |   |___ review |   |   |   |___ delete |   |   | |   | |   |___ scheduled |   |   |___ admin |   |   |   |___ delete |   |   |   |___ review |   |   | |   |   |___ editor |   |   |   |___ review |   |   |   |___ delete |   |   | |   | | |___ pressrelease |   |___ scheduled |   |   |___ admin |   |   |   |___ delete |   |   |   |___ review (i spend far time on ascii tree ...) 

you can walk 3 "down" node node , check children.

this way, can check states possible on blog-entry , (if re-order or create tree in different fashion) can check things admin can on article.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -