in our app we have a Json file that contains several properties used for menu configuration. One of the keys should tell us if a menu item should be displayed. The thing is that the value for this key, can be an int but written as String "0" or "1", a Boolean written as String "true", "false", or an URL. So depending on the item, one of these 3 'magic' values tell us if a specific item should be displayed or not.
My question is, what is the best way or the elegant way of knowing the type of this value? We need to know the type for different handling.
At first I created a method for checking if the value is of Boolean type.
return value.equals(true.toString()) || value.equals(false. toString()));
The same, I should create a method if it is int, but for checking if it's a URL is a bit tricky.
So because I didn't find this approach very elegant and readable, I decided to add the type of this 'magic' key in the Json file: For Boolean type I added:
"myKeyType": "boolean"
And so on for the other 2. So I would like to know if adding a type property to Json file is a good idea, if it's Json responsibility to tell us the type, or is there a better way to do this?
EDIT: I can't change the type of data I receive, so I have to deal with the scenario I described. In this case, which of the 2 solutions I tried is more elegant? The first one, or the 2nd one with the extra key?
Thanks
Object
s and have to do all the type switching at runtime? 3) Why the strings "true"/"false" instead of just true/false?