0

I am making a simple phone book system where user and admin inputs via command prompt. I am using a login.json file that has got just this -

{ "username" : "admin", "password" : "12345" }

I want to know whats the best way in java 8 now to read the json file and check if the user is admin or not.

I would also want to know how can i store the DOB given by a user in java 8 LocalDate API, if we can. I have a model user class that has all the fields but not sure how the LocalDate from java 8 would help me set the date passed from command prompt, seems we have to do some parsing there ??

Thanks in advance

  • 2
    Will this help - https://stackoverflow.com/a/18998203/919158 to read json? Is DOB coming in JSON file? – kann Mar 03 '20 at 21:06
  • additionally to the post above if you use gson for parsing you can register an Adapter for LocalDate [serialize-java-8-localdate-as-yyyy-mm-dd-with-gson](https://stackoverflow.com/questions/39192945/serialize-java-8-localdate-as-yyyy-mm-dd-with-gson) – Sergej Masljukow Mar 03 '20 at 21:47
  • @kann DOB is coming from console entered by user, but i think i did it using - System.out.println("Please provide DOB of the user (mm/dd/yyyy) : "); String dateString = s.next(); SimpleDateFormat df = new SimpleDateFormat("mm/dd/yyyy"); try { Date dateOfBirth= df.parse(dateString); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } – manvendra dubey Mar 03 '20 at 22:59
  • @manvendradubey I just Shaw your question but could you please clear me, how user enters input from command line(one-by-one/json file?) e.g. enter username then you read it and then enter pass again read that like that and how you get above mentioned json? – Sandeep Tiwari Mar 04 '20 at 03:42
  • @SandeepTiwari i am reading it line by line from console using FastReader class, but the json is just a hardcoded file that has user name and pass to validate if the user entered the admin credential or not, that is it – manvendra dubey Mar 04 '20 at 16:55

0 Answers0