package ru.job4j.servlets;

import ru.job4j.servlets.userstore.User;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.*;
import java.util.concurrent.ConcurrentHashMap;
import com.fasterxml.jackson.databind.ObjectMapper;

public class ItemsController extends HttpServlet {

    private final static String baseFile = "user.json";
    ConcurrentHashMap<String, User> map = new ConcurrentHashMap<>();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        req.getRequestDispatcher("/WEB-INF/jsp/Items.html").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader reader = req.getReader();
        ObjectMapper mapper = new ObjectMapper();
        User user = mapper.readValue(req.getInputStream(), User.class);
    }
}

@@ -279,16 +279,39 @@
 a.io.*;%0A
+import java.util.Date;%0A
 import j
@@ -349,16 +349,16 @@
 ashMap;%0A
-
 import c
@@ -580,16 +580,233 @@
 p%3C%3E();%0A%0A
+    public static void toJSON(User user) throws IOException %7B%0A        ObjectMapper mapper = new ObjectMapper();%0A        mapper.writeValue(new File(baseFile), user);%0A        System.out.println(%22json created!%22);%0A    %7D%0A%0A
     @Ove
@@ -1187,57 +1187,8 @@
 n %7B%0A
-        BufferedReader reader = req.getReader();%0A
     
@@ -1257,44 +1257,202 @@
 r = 
-mapper.readValue(req.getInputStream(
+new User(0, %22name%22, %22login%22, req.getParameter(%22email%22), new Date(), req.getParameter(%22pwd%22), 1);%0A        toJSON(user);%0A        map.put(req.getParameter(%22pwd%22), mapper.readValue(new File(baseFile
 ), U
@@ -1461,17 +1461,20 @@
 r.class)
-;
+);%0A%0A
 %0A    %7D%0A%7D

task #58534