Is there a data-structure similar to JSON in JAVA? [closed] Is there a data-structure similar to JSON in JAVA? [closed] json json

Is there a data-structure similar to JSON in JAVA? [closed]


If you want a 'generic' collection, why not use a Guava MultiMap ?

A collection that maps keys to values, similar to Map, but in whicheach key may be associated with multiple values. You can visualize thecontents of a multimap either as a map from keys to nonemptycollections of values ... or as a single "flattened" collection of key-value pairs

However, it sounds like you may really want to model your entities as proper objects, with the appropriate attributes etc. Storing collections of collections of collections will work, but you'll lose some of the benefits of defining objects with behaviour/polymorphism etc.

e.g.

List<Product> products = ...products.add(new Book(...));products.add(new Dvd(...));

(or perhaps a map of stock item id to object instance, or, or, or...)

I would treat JSON as a representation of your object (e.g. like XML). If you need to transport or store these objects, translate them to a format such as JSON or XML. But manage them within your program using objects with type and behaviour.


You need a MultiMap, not present by default in Java but you can find it in libraries like Guava or Apache Commons.


As @maskacovnik wrote- use your own class :)

Btw you can also work with JSON in java - API docs there

If you need some container you can use also a hashMap - with all values saved as string eg. (for multi-valued keys you can use value in format eg. csv ..)

Example of Hashmap data structure:

name - namesurname - surnamefunctions - func1;funct2,etc..

And while you will need to read values of keys, you can parse them into array by string.split(regex)