package com.github.kpavlov.restws.server.controller;

import com.github.kpavlov.restws.server.model.*;
import com.github.kpavlov.restws.server.model.Error;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@RestController
public class EchoController {


    @RequestMapping(value = "/api/echo",
            method = RequestMethod.POST,
            consumes = {MediaType.APPLICATION_JSON_VALUE,
                    "application/vnd.api+json"},
            produces = MediaType.APPLICATION_JSON_VALUE
    )
    AbstractResponseWrapper<Foo> echo(@RequestBody @Valid FooRequestWrapper request,
                                      BindingResult bindingResult,
                                      HttpServletResponse httpServletResponse) {

        final AbstractResponseWrapper<Foo> response = new FooResponseWrapper();

        if (bindingResult.hasErrors()) {

            bindingResult.getFieldErrors().forEach(e -> {
                final Error error = new Error();
                error.addPointerSource(e.getField());
                error.setTitle("Invalid Attribute");
                error.setDetail(e.getDefaultMessage());
                response.addError(error);
            });

            httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return response;
        }

        System.out.println("request = " + request);

        response.setData(request.getData());

        System.out.println("bindingResult = " + bindingResult.getFieldErrors());


        return response;
    }


}

@@ -149,16 +149,41 @@
 .Error;%0A
+import org.slf4j.Logger;%0A
 import o
@@ -602,54 +602,199 @@
 d;%0A%0A
-@RestController%0Apublic class EchoController %7B%0A
+import static org.slf4j.LoggerFactory.getLogger;%0A%0A@SuppressWarnings(%22unused%22)%0A@RestController%0Apublic class EchoController %7B%0A%0A    private final Logger logger = getLogger(EchoController.class);
 %0A%0A  
@@ -1397,16 +1397,103 @@
 ors()) %7B
+%0A            logger.debug(%22bindingResult.errors = %7B%7D%22, bindingResult.getFieldErrors());
 %0A%0A      
@@ -1942,34 +1942,28 @@
         
-System.out.println
+logger.trace
 (%22reques
@@ -1966,19 +1966,20 @@
 quest = 
-%22 +
+%7B%7D%22,
  request
@@ -2032,91 +2032,8 @@
 );%0A%0A
-        System.out.println(%22bindingResult = %22 + bindingResult.getFieldErrors());%0A%0A%0A
     

use slf4j logger in EchoController