Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+33 votes

I’m talking about mutating a Json object back to be an object of the respective class (just as we did in class) I, was thinking creating the constructor would be simply a best choice, but I have no arguments to back that up. Both options seem equally as OK.

asked in CSC285_Fall2018 by (8 points)

1 Answer

+18 votes
 
Best answer

Well it probably would be best to do it static because if you make a constructor you would have to assign each object from the JSON object to the data fields. I don't know how this would work because you end up with an Object that has a bunch of smaller Objects in it and I don't know if the constructor would be smart enough to realize that it is a ProjectData object and set those things together, especially if you forget about the VideoCapture object because then it really won't create the ProjectData correctly. Also, there already is a constructor that takes in only a String parameter, which means you would have to add maybe a boolean parameter to whether it is a JSON String or a fileName String. Then you would have to change that in all of your coding. Also, JSON may be using the constructor to make the object to begin with.

Short answer, it probably is best to make it a static method especially since it is already of that type (ProjectData in this scenario), just written in a JSON String instead of Java code.

I would wait for a possibly better answer from Stonedahl, those are my thoughts, but not 100% sure if they're 100% accurate.

answered by (8 points)
selected by
...