Index: src/main/groovy/com/lemans/correspondence/controllers/FormSubmitController.groovy =================================================================== diff -u -r7bd1000a98e60401332f1115b3b2fe4c22fff7ae -rbdd638737b74c8e57e6d2f4bcb4d7a7458acb9bb --- src/main/groovy/com/lemans/correspondence/controllers/FormSubmitController.groovy (.../FormSubmitController.groovy) (revision 7bd1000a98e60401332f1115b3b2fe4c22fff7ae) +++ src/main/groovy/com/lemans/correspondence/controllers/FormSubmitController.groovy (.../FormSubmitController.groovy) (revision bdd638737b74c8e57e6d2f4bcb4d7a7458acb9bb) @@ -1,11 +1,9 @@ package com.lemans.correspondence.controllers +import com.fasterxml.jackson.databind.ObjectMapper import com.lemans.api.LeMansApiController import com.lemans.correspondence.services.DomainFormService import com.lemans.correspondence.services.FormSubmitService -import org.apache.logging.slf4j.SLF4JLogger -import org.slf4j.Logger -import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping @@ -26,16 +24,13 @@ @Autowired FormSubmitService formSubmitService - private static final Logger log = LoggerFactory.getLogger(FormSubmitController.class) - @PostMapping("/domain/{domainId}/form/{formKey}/submit") - def add(@PathVariable Integer domainId, @PathVariable String formKey, @RequestHeader("Content-Type") String contentType, @RequestBody(required = false) Map input, @RequestParam(required = false) Map params) { + def add(@PathVariable Integer domainId, @PathVariable String formKey, @RequestHeader("Content-Type") String contentType, @RequestBody(required = false) String input, @RequestParam(required = false) Map params) { Map formData = [:] - log.debug("domainId: ${domainId} formKey: ${formKey} contentType: ${contentType} input: ${input} params: ${params}") if (contentType.contains('multipart/form-data') || contentType.contains('application/x-www-form-urlencoded')) { formData = extractFormData(params) } else { - formData = extractFormData(input) + formData = extractFormData(new ObjectMapper().readValue(input, Map.class)) } Map domainForm = domainFormService.findForm([domainId: domainId, formKey: formKey]) if (domainForm) { @@ -48,6 +43,8 @@ } else { notFound(unknownDomainForm()) } } + + private Map extractFormData(Map inputData) { Map sortedData = sortFormData(inputData) sortedData?.collectEntries {