com.fasterxml.jackson.core.JsonParseException:意外的字符('='(代码61))

时间:2017-02-22 12:18:48

标签: java jquery spring jackson

我正在使用ParamQuery供应商的网格组件。 我的spring控制器接受使用Jackson库转换为DepartmentHeadDTO(Pojo类)的JSON数据。

当我使用AJAX发出此类请求时,它会被执行。

请求:

 dataModel: {
                location: "remote",
                sorting: "local",
                dataType: "JSON",
                url: "/ExpenseManagement/departmentHead", 
                method: "POST",
                beforeSend: function(xhr) {                 
                       xhr.setRequestHeader("Accept", "application/json");
                       xhr.setRequestHeader("Content-Type", "application/json");
                   },
                error: function () {
                    //$gridMain.pqGrid( 'rowInvalidate', { rowData: rowData });
                },

                postData: JSON.stringify(jsonToBeSend),
                //url = "/pro/orderdetails.php?orderId=" + orderID //for PHP
            },
            colModel: [
                { title: "BranchName", width: 80, dataIndx: "departmentId" }

            ],

JSON DATA:

var jsonToBeSend=new Object();
      jsonToBeSend["branchId"] = "1";

SPRING控制器:

    @RequestMapping(value="/departmentHead",method=RequestMethod.POST)
public @ResponseBody List<DepartmentHeadDTO> getDepartmentHead(@RequestBody DepartmentHeadDTO receivedDepartmentHeadDTO){
    List<DepartmentHeadDTO> departmentHeadDTOList = null;
    LoginUserDetails user = (LoginUserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    if(Validation.validateForNullObject(user.getLoginDTO().getEmployeeDTO())){

         departmentHeadDTOList = deptHeadSerrvice.findDepartmentHeadUnderCompany(receivedDepartmentHeadDTO);
    }

    return departmentHeadDTOList;
}

POJO课程:

public class DepartmentHeadDTO extends BaseDTO {

private static final long serialVersionUID = 1L;

private Long deptHeadId;

private Long departmentId;
private DepartmentDTO departmentDTO;


private Long branchId;
private BranchDTO branchDTO;


private Long employeeId;
private EmployeeDTO employeeDTO;


public DepartmentDTO getDepartmentDTO() {
    return departmentDTO;
}

public void setDepartmentDTO(DepartmentDTO departmentDTO) {
    this.departmentDTO = departmentDTO;
    this.departmentId=this.departmentDTO.getDepartmentId();
}

public BranchDTO getBranchhDTO() {
    return branchDTO;
}

public void setBranchhDTO(BranchDTO branchhDTO) {
    this.branchDTO = branchhDTO;
    this.branchId =branchhDTO.getBranchId();
}

public EmployeeDTO getEmployeeDTO() {
    return employeeDTO;
}

public void setEmployeeDTO(EmployeeDTO employeeDTO) {
    this.employeeDTO = employeeDTO;
    this.employeeId= employeeDTO.getEmployeeId();
}

public Long getDeptHeadId() {
    return deptHeadId;
}

public void setDeptHeadId(Long deptHeadId) {
    this.deptHeadId = deptHeadId;
}

public Long getDepartmentId() {
    return departmentId;
}

public void setDepartmentId(Long departmentId) {
    this.departmentId = departmentId;
    DepartmentDTO deptDTO= new DepartmentDTO();
    deptDTO.setDepartmentId(departmentId);
    this.departmentDTO=deptDTO;
}

public Long getBranchId() {
    return branchId;
}

public void setBranchId(Long branchId) {
    this.branchId = branchId;
    BranchDTO branchDTO= new BranchDTO();
    branchDTO.setBranchId(branchId);
    this.branchDTO=branchDTO;
}

public Long getEmployeeId() {
    return employeeId;
}

public void setEmployeeId(Long employeeId) {
    this.employeeId = employeeId;
    EmployeeDTO empDTO=new EmployeeDTO();
    empDTO.setEmployeeId(employeeId);
    this.employeeDTO=empDTO;
}

ERROR:

    17:43:46.042 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /departmentHead
17:43:46.042 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Returning handler method [public java.util.List<com.chaitanya.departmentHead.model.DepartmentHeadDTO> com.chaitanya.web.controller.DepartmentHeadController.getDepartmentHead(com.chaitanya.departmentHead.model.DepartmentHeadDTO)]
17:43:46.042 DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'departmentHeadController'
17:43:46.118 DEBUG o.s.w.s.m.m.a.RequestResponseBodyMethodProcessor - Reading [class com.chaitanya.departmentHead.model.DepartmentHeadDTO] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@73c69ca0]
17:43:46.128 DEBUG o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Resolving exception from handler [public java.util.List<com.chaitanya.departmentHead.model.DepartmentHeadDTO> com.chaitanya.web.controller.DepartmentHeadController.getDepartmentHead(com.chaitanya.departmentHead.model.DepartmentHeadDTO)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unexpected character ('=' (code 61)): Expected space separating root-level values
 at [Source: java.io.PushbackInputStream@38cdbe4a; line: 1, column: 3]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('=' (code 61)): Expected space separating root-level values
 at [Source: java.io.PushbackInputStream@38cdbe4a; line: 1, column: 3]
17:43:46.130 DEBUG o.s.w.s.m.a.ResponseStatusExceptionResolver - Resolving exception from handler [public java.util.List<com.chaitanya.departmentHead.model.DepartmentHeadDTO> com.chaitanya.web.controller.DepartmentHeadController.getDepartmentHead(com.chaitanya.departmentHead.model.DepartmentHeadDTO)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unexpected character ('=' (code 61)): Expected space separating root-level values
 at [Source: java.io.PushbackInputStream@38cdbe4a; line: 1, column: 3]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('=' (code 61)): Expected space separating root-level values
 at [Source: java.io.PushbackInputStream@38cdbe4a; line: 1, column: 3]
17:43:46.130 DEBUG o.s.w.s.m.s.DefaultHandlerExceptionResolver - Resolving exception from handler [public java.util.List<com.chaitanya.departmentHead.model.DepartmentHeadDTO> com.chaitanya.web.controller.DepartmentHeadController.getDepartmentHead(com.chaitanya.departmentHead.model.DepartmentHeadDTO)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unexpected character ('=' (code 61)): Expected space separating root-level values
 at [Source: java.io.PushbackInputStream@38cdbe4a; line: 1, column: 3]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('=' (code 61)): Expected space separating root-level values
 at [Source: java.io.PushbackInputStream@38cdbe4a; line: 1, column: 3]
17:43:46.130 DEBUG o.s.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
17:43:46.131 DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request

请帮我摆脱它。感谢。

0 个答案:

没有答案