Java JSON Node Programming Spring Boot

My friend JavaScript Object Notation

One of the best (and probably worst) things of working with Node is that it’s just JavaScript. Why is that a good thing given the reputation of JS? For me it has to be the native support of JSON. It makes sending and receiving data from server to client such a breeze.

It’s not that it is something like borderline impossible to work with JSON with other languages but I find it a lot more difficult. Especially with statically typed languages such as Java. It’s not such a big thing when the JSON in question is simple but the more complex it is the harder it gets. Or I am doing something really wrong (which wouldn’t be a surprise given my less-than-average [programming] skills).

Not so long ago I ended up making a endpoint for receiving data from client at work. The JSON isn’t even that complex but I ended up having a lot of problems with it anyways. Actually by the time I am writing this it is not ready so eveyrthing might change later on. But anyways. The JSON in question looks something like this:

{

“key”: [ {“name”: “example”, “value”: “123”}, {“name”: “example2”, “value”: “1233”} ],

“key2”: [ {“name”: “example3”, “value”: “12”}, {“name”: “example4”, “value”: “1”} ]

}

The arrays were longer of course but you get the gist. So that ended up to being this in Java:

ArrayList< HashMap < String, ArrayList < CustomJavaClass>>>

Not that pretty. And on top of that I have some serious problems deciding the types what to use but that is most likely because of my limited knowledge of Java data types. I hope that this gets easier when I get more experience with Java.

EDIT: Scratch that. I decided to make a wrapper class. The class has two properties:
HashMap< String, String> and ArrayList< CustomJavaClass>

Made things a lot easier.

PS. My project is getting along rather nicely. I will write about it more soon. Maybe.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top