• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tree implementation in java  RSS feed

 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Team,

I have a json object as below, i have to iterate the object and get the unique list of 'label' {label1, label2} and when i select the label 'label1' i need to get the unique list of 'id' {121, 122} and when i select the id '121' i need to get the unique list of 'ip' from the 'items' and when i select the ip ''xx.xx.xx1' i need to get the unique list of 'descirption'

so when i select label1 -- id: {121, 122} -- and on selecting id - 121 -- i should display list of 'ip' for this combination { 'xx.xx.1', 'xx.xx.xx2', 'xx.xx.8'} and when i select the ip - 'xx.xx.1' i should display the list of 'desc' { 'xxxx', 'yyyy', 'aaaa'}

Let me know how i can implement this in java with high performance and scalability.

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
prabhu pandurangan wrote:Let me know how i can implement this in java with high performance and scalability.

I'm afraid I'm no JSON expert, but one thing I will suggest: Get the implementation right first; then worry about performance and scalability.

However, looking at the structure, It would appear to be a set of Nodes, each of which contains a list of Labels, each of which contains a list of Items, each of which contains a list of IP descriptors. Now you say that each IP might contain a list of descriptions, but I don't see any evidence of that from what you've shown us - on the contrary: each IP would appear to have only ONE description.

So, you would appear to have four types: Node, Label, Item and IP (or IPDescriptor).

I'm afraid I'm not familiar enough with the various brackets ([]) and braces ({}) in JSON to know exactly what they mean though - the braces seem to denote a "list" of some kind, but whether it's a List (java.util.List), a Set (java.util.Set), or a Map (java.util.Map), I simply don't know; and the choice could be important.

Hope it helps (as far as it goes).

Winston

[Edit] One thought occurred to me: Presumably, these JSON objects came from somewhere; why not look at the classes/objects that produced them?
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:I'm afraid I'm not familiar enough with the various brackets ([]) and braces ({}) in JSON to know exactly what they mean though - the braces seem to denote a "list" of some kind, but whether it's a List (java.util.List), a Set (java.util.Set), or a Map (java.util.Map), I simply don't know; and the choice could be important.

Technically, [] means "array", but in Java code you can use an array or any collection type (at least in most JSON mapping libraries). {} means "object", mostly mapped to a custom object, but you can often also use a Map.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Technically, [] means "array", but in Java code you can use an array or any collection type (at least in most JSON mapping libraries). {} means "object", mostly mapped to a custom object, but you can often also use a Map.

Oh, OK. Thanks for that.

Winston
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
best way to implement this??
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best way to implement?
Use a library such as jackson to parse the JSON into java objects.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!