If you have a string that you read which you need to convert into a two-dimensional array, then you probably think of dealing with complicated regular expressions.
You start to also think about the edge cases: what if an opening or closing bracket is not included, or what if there is a missing comma, etc.
However, fortunately, there are helpful libraries that can help you with just that.
You don’t need to deal with complicated regular expressions and sweating about all the possible edge cases that you need to save in the logs and only later on go through them
Jackson library has a class with one very useful method that can help you with such cases.
Let’s say that you have the following:
Initially, you need to import the Jar file of Jackson. I am going to do that via Maven:
After that, all you have to do is call the method readValue() from an object of the class ObjectMapper
That’s it. You don’t need to deal with a lot more stuff in there.
I hope you find this helpful.