commit 455af7b1dbeac6483e7d17b64c9f9f4cdfa2e44c
Author: Tomáš Šimandl <tomas.simandl@gmail.com>
Date:   Tue Jan 22 17:01:13 2019 +0100

    Removed org.json dependency
    
    + changed to gson

diff --git a/sources/pom.xml b/sources/pom.xml
index 0b58d1b..fda63e8 100644
--- a/sources/pom.xml
+++ b/sources/pom.xml
@@ -151,14 +151,7 @@
             <version>2.4</version>
             <classifier>jdk15</classifier>
         </dependency>
-        <!-- https://mvnrepository.com/artifact/org.json/json -->
-        <dependency>
-            <groupId>org.json</groupId>
-            <artifactId>json</artifactId>
-            <version>20180813</version>
-        </dependency>
-
-
+        
 
         <!-- Database -->
         <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetDBDiagram.java b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetDBDiagram.java
index a73a748..b860f77 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetDBDiagram.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetDBDiagram.java
@@ -1,12 +1,12 @@
 package cz.zcu.kiv.offscreen.servlets.api;
 
 import com.google.common.base.Strings;
+import com.google.gson.Gson;
 import cz.zcu.kiv.offscreen.servlets.BaseServlet;
 import cz.zcu.kiv.offscreen.user.DB;
 import cz.zcu.kiv.offscreen.user.Diagram;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-import org.json.JSONObject;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -39,12 +39,12 @@ public class GetDBDiagram extends BaseServlet {
             return;
         }
 
-        JSONObject json = new JSONObject(diagram.getDiagram());
+        String json = new Gson().toJson(diagram.getDiagram());
 
         response.setContentType("application/json");
         response.setCharacterEncoding("UTF-8");
         response.setStatus(HttpServletResponse.SC_OK);
-        response.getWriter().write(json.toString());
+        response.getWriter().write(json);
         response.getWriter().flush();
         logger.debug("Response OK");
     }
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetPrivateDiagrams.java b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetPrivateDiagrams.java
index 41d1e74..2add421 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetPrivateDiagrams.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/GetPrivateDiagrams.java
@@ -1,12 +1,12 @@
 package cz.zcu.kiv.offscreen.servlets.api;
 
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
 import cz.zcu.kiv.offscreen.servlets.BaseServlet;
 import cz.zcu.kiv.offscreen.user.DB;
 import cz.zcu.kiv.offscreen.user.Diagram;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-import org.json.JSONArray;
-import org.json.JSONObject;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -34,15 +34,20 @@ public class GetPrivateDiagrams extends BaseServlet {
         int loggedUserId = getUserId(request);
         List<Map<String, String>> userDiagramList = diagram.getDiagramListByUserId(loggedUserId);
 
-        JSONArray json = new JSONArray();
+        JsonArray jsonArray = new JsonArray();
         for (Map<String, String> userDiagram : userDiagramList) {
-            json.put(new JSONObject(userDiagram));
+
+            JsonObject jsonObject = new JsonObject();
+            jsonObject.addProperty("id", userDiagram.get("id"));
+            jsonObject.addProperty("name", userDiagram.get("name"));
+
+            jsonArray.add(jsonObject);
         }
 
         response.setContentType("application/json");
         response.setCharacterEncoding("UTF-8");
         response.setStatus(HttpServletResponse.SC_OK);
-        response.getWriter().write(json.toString());
+        response.getWriter().write(jsonArray.toString());
         response.getWriter().flush();
         logger.debug("Response OK");
 
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/Login.java b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/Login.java
index d45de8b..7dc4ea6 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/Login.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/Login.java
@@ -1,20 +1,18 @@
 package cz.zcu.kiv.offscreen.servlets.api;
 
 import com.google.common.base.Strings;
+import com.google.gson.JsonObject;
 import cz.zcu.kiv.offscreen.servlets.BaseServlet;
 import cz.zcu.kiv.offscreen.user.DB;
 import cz.zcu.kiv.offscreen.user.User;
 import cz.zcu.kiv.offscreen.vo.UserVO;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-import org.json.JSONObject;
+
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
 public class Login extends BaseServlet {
     private static final Logger logger = LogManager.getLogger();
 
@@ -24,19 +22,19 @@ public class Login extends BaseServlet {
         String username = request.getParameter("username");
         String password = request.getParameter("password");
 
-        Map<String, String> errors = new HashMap<>();
+        JsonObject errors = new JsonObject();
 
         if (Strings.isNullOrEmpty(username)) {
-            errors.put("username", "Please enter username.");
+            errors.addProperty("username", "Please enter username.");
             logger.debug("Empty user name");
         }
 
         if (Strings.isNullOrEmpty(password)) {
-            errors.put("password", "Please enter password.");
+            errors.addProperty("password", "Please enter password.");
             logger.debug("Empty password");
         }
 
-        if (errors.isEmpty()) {
+        if (errors.size() == 0) {
             DB db = new DB(getServletContext());
             User user = new User(db);
 
@@ -49,11 +47,10 @@ public class Login extends BaseServlet {
                 request.getSession().setAttribute("userId", userVO.getId());
                 request.getSession().setAttribute("user", userVO);
 
-                Map<String, Object> userMap = new HashMap<>();
-                userMap.put("id", user.getId());
-                userMap.put("username", user.getNick());
+                JsonObject json = new JsonObject();
+                json.addProperty("id", user.getId());
+                json.addProperty("username", user.getNick());
 
-                JSONObject json = new JSONObject(userMap);
 
                 response.setContentType("application/json");
                 response.setCharacterEncoding("UTF-8");
@@ -72,8 +69,8 @@ public class Login extends BaseServlet {
             }
 
         } else {
-            JSONObject json = new JSONObject();
-            json.put("error", new JSONObject(errors));
+            JsonObject json = new JsonObject();
+            json.add("error", errors);
 
             response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
             response.setContentType("application/json");
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/Register.java b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/Register.java
index 44adc66..15c6f09 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/Register.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/Register.java
@@ -1,12 +1,13 @@
 package cz.zcu.kiv.offscreen.servlets.api;
 
 import com.google.common.base.Strings;
+import com.google.gson.JsonObject;
 import cz.zcu.kiv.offscreen.servlets.BaseServlet;
 import cz.zcu.kiv.offscreen.user.DB;
 import cz.zcu.kiv.offscreen.user.User;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-import org.json.JSONObject;
+
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -34,49 +35,49 @@ public class Register extends BaseServlet {
 		DB db = new DB(getServletContext());
 		User user = new User(db);
 
-		Map<String, String> errors = new HashMap<>();
+		JsonObject errors = new JsonObject();
 
 		if (Strings.isNullOrEmpty(name)) {
-			errors.put("name", "Please enter name.");
+			errors.addProperty("name", "Please enter name.");
 			logger.debug("Empty name");
 		}
 
 		if (Strings.isNullOrEmpty(email)) {
-			errors.put("email", "Please enter e-mail address.");
+			errors.addProperty("email", "Please enter e-mail address.");
 			logger.debug("Empty e-mail address");
 
 		} else if (!isEmailAddressValid(email)) {
-			errors.put("email", "Please enter valid e-mail address.");
+			errors.addProperty("email", "Please enter valid e-mail address.");
 			logger.debug("Invalid e-mail address");
 
 		} else if (user.isEmailExists(email)) {
-			errors.put("email", "E-mail already exists.");
+			errors.addProperty("email", "E-mail already exists.");
 			logger.debug("E-mail exists");
 		}
 
 		if (Strings.isNullOrEmpty(username)) {
-			errors.put("username", "Please enter username.");
+			errors.addProperty("username", "Please enter username.");
 			logger.debug("Empty user name");
 
 		} else if (user.isNickExists(username)) {
-			errors.put("username", "Nickname already exists.");
+			errors.addProperty("username", "Nickname already exists.");
 			logger.debug("Username(nickname) exists");
 		}
     	
     	if (Strings.isNullOrEmpty(password) || Strings.isNullOrEmpty(passwordCheck)) {
-    		errors.put("password", "Please enter password.");
+    		errors.addProperty("password", "Please enter password.");
 			logger.debug("Empty password");
 
 		} else if (password.length() < 5) {
-    		errors.put("password", "Passwords must be at least 5 characters long.");
+    		errors.addProperty("password", "Passwords must be at least 5 characters long.");
 			logger.debug("Invalid password");
 
 		} else if (!password.equals(passwordCheck)) {
-			errors.put("passwordCheck", "Passwords must be equal.");
+			errors.addProperty("passwordCheck", "Passwords must be equal.");
 			logger.debug("Passwords not match");
 		}
 
-    	if (errors.isEmpty()) {
+    	if (errors.size() == 0) {
     		Map<String, String> userMap = new HashMap<>();
     		userMap.put("name", name);
     		userMap.put("email", email);
@@ -90,8 +91,8 @@ public class Register extends BaseServlet {
 			logger.debug("User created");
 
 		} else {
-			JSONObject json = new JSONObject();
-			json.put("error", new JSONObject(errors));
+    		JsonObject json = new JsonObject();
+    		json.add("error", errors);
 
 			response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
 			response.setContentType("application/json");
diff --git a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/SaveDiagram.java b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/SaveDiagram.java
index a7d99fa..73a7aba 100644
--- a/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/SaveDiagram.java
+++ b/sources/src/main/java/cz/zcu/kiv/offscreen/servlets/api/SaveDiagram.java
@@ -1,12 +1,13 @@
 package cz.zcu.kiv.offscreen.servlets.api;
 
 import com.google.common.base.Strings;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
 import cz.zcu.kiv.offscreen.servlets.BaseServlet;
 import cz.zcu.kiv.offscreen.user.DB;
 import cz.zcu.kiv.offscreen.user.Diagram;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-import org.json.JSONObject;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -71,12 +72,13 @@ public class SaveDiagram extends BaseServlet {
         logger.debug("Diagram created or updated.");
 
         // send response
-        JSONObject json = new JSONObject(diagram.getDiagram());
+
+        String json = new Gson().toJson(diagram.getDiagram());
 
         response.setContentType("application/json");
         response.setCharacterEncoding("UTF-8");
         response.setStatus(HttpServletResponse.SC_OK);
-        response.getWriter().write(json.toString());
+        response.getWriter().write(json);
         response.getWriter().flush();
         logger.debug("Response OK");
     }
