jiuntian / IssueTrackerAssignment

0 stars 0 forks source link

What is JSON? How to handle it? #4

Open jiuntian opened 3 years ago

jiuntian commented 3 years ago

JSON is JavaScript Object Notation. It is actually a Map data structure to store the data, with key value pair. Each JSON object is a Map<String, Object> object, where Object can be any class that is suitable.

For example you have a Class Person, where it's attribute is name, age; and a House class with its attribute persons, which is a List.

Class Person {
    string name;
    int age;
}

Class House {
    List<Person> persons;
}

and then your json file grayhouse.json could be like this:

{
    "persons": [
        {"name": "Ali bin Abu",
         "age": 43
        },
        {"name":"Siti Fatimah",
         "age":32
        }
    ]
}

What you should do to parse the json file is to:

  1. Read the json file
  2. Parse this grayhouse.json into an House object, and multiple Person object in the List in House.
  3. You may use library for your json object serialisation and deserialisation.

Your code should be able to Deserialise (read object into Java Object from json string), and Serialise (write Java Object into json string, which mean u save all your data into Json file as a file database).

You should did Google Search when you are encountering problem, before start to ask demo, as one of the learning objective of this assignment is problem solving skill. However, don't be hesitate to ask demo if you have any problem that cannot be solved by using Google Search.

Some resources you may refer to:

  1. https://www.baeldung.com/jackson-object-mapper-tutorial
  2. https://www.baeldung.com/jackson-deserialization
  3. http://tutorials.jenkov.com/java-json/jackson-objectmapper.html
  4. Google search json deserialization/serialization

Thanks.

lohyenshen commented 3 years ago

Hi there, I am using MySQL as my data storage.

Can I modify the json file (https://jiuntian.com/data.json) from this link to suit the implementation of jdbc? I would retain the same information but with different implementation.

jiuntian commented 3 years ago

You do not have to modify the JSON structure to store the data in SQL databases. Store each class of object in one table and reference by primary and foreign key. You can write your own function to insert the entries to database, but you can also use libraries like Hibernate or JPA to ease your work.

Some resources: https://www.javatpoint.com/hibernate-tutorial https://docs.jboss.org/hibernate/orm/current/quickstart/html_single/ https://www.tutorialspoint.com/hibernate/index.htm

Since Database Management System course might not been taken by first year student, I include some of the resource just in case. Brief introduction to database: http://www.upi.pr.it/docs/easfg/easvrfgp7.htm

Since External Database is part of extra requirements, we want you to show your extraordinary in getting A+. However, you can also try NoSQL database like mongodb, which will be easier to deal with JSON as it store data as document (JSON).

You can modify JSON structure to add feature, but not this.

Hope this helps. Good luck in learning in modern Java Programming. Feel free to ask if any further questions or difficulties.

On Sun, May 16, 2021, 4:52 PM shenshen1122 @.***> wrote:

Hi there, I am using MySQL as my data storage.

Can I modify the json file (https://jiuntian.com/data.json) from this link to suit the implementation of jdbc? I would retain the same information but with different implementation.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jiuntian/IssueTrackerAssignment/issues/4#issuecomment-841788386, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADJ2E72EV3UYMQRNXBOJ7MTTN6BVJANCNFSM445SHXFA .

lohyenshen commented 3 years ago

Hi there, I misspoke in the earlier comment. What I meant is given that I will be referencing primary key with foreign key in tables in database. Can I change the the "name of the attribute" without altering the "value" in json file.

For example the changes in (issue) "id" -> "issueID"

I will also add "projectID" - to reference PK in project table "creatorID" , "assigneeID" - to reference PK in user table

Are the above changes in json file allowed?

jiuntian commented 3 years ago

Can

Terence440 commented 3 years ago

image

Good day, I wanna to ask about the database, is that an extra features or not? Cause in the question said that "Your program should at least be able to read the provided initial data into your own local database.".

jiuntian commented 3 years ago

Hi,

"Your program should at least be able to read the provided initial data into your own local database."

This mean that, your problem should at least, be able to read the data.json, and made changes/update to it, as a local file database.

While the external database, like MySQL, will be a part of extra requirement, which will bring extra values to your work.

Terence440 commented 3 years ago

Just want to confirm with you, the local file database meaning that we can write it into .txt or .csv right?

jiuntian commented 3 years ago

json

On Wed, May 19, 2021, 10:59 AM Terence440 @.***> wrote:

Just want to confirm with you, the local file database meaning that we can write it into .txt or .csv right?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jiuntian/IssueTrackerAssignment/issues/4#issuecomment-843706073, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADJ2E76KILNIGNKXJPXSTGLTOMSQZANCNFSM445SHXFA .

Terence440 commented 3 years ago

alright thank you

Terence440 commented 3 years ago

Good day, just want to ask about the time stamp. In the data.json it showing this kind of time stamp -> "timestamp": 1567340520 Can we write into another form like -> Sat May 22 23:47:16 MYT 2021

jiuntian commented 3 years ago

is there problems to parse and write in UNIX timestamps?

Terence440 commented 3 years ago

I got it, thank you @jiuntian .