[Ajax] HttpMessageNotReadableException: JSON parse error: Unrecognized token 'firstName': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false');

2021. 2. 16. 22:50Coding

728x90

 

1
2
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized token 'firstName': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'firstName': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (PushbackInputStream); line: 1, column: 11]]
cs

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
providerVo = {
            firstName: firstName,
            lastName: lastName,
            phone: phone,
            country: country,
            companyName: companyName,
            addr1: addr
        };
 
 $.ajax({
           url: "/update",
            data: providerVo,
            dataType: 'json',
            contentType: 'application/json',
            type: 'post'
...
 
cs

대충 이런 코드에서... 

 

1
2
3
4
5
6
7
8
providerVo = JSON.stringify({
            firstName: firstName,
            lastName: lastName,
            phone: phone,
            country: country,
            companyName: companyName,
            addr1: addr
        });
cs

data에 해당하는 providerVo에 JSON.stringfy()만 해주면된다.

 

ajax가 바로 object를 인식못해서 생기는 문제인듯.
json으로 바꿔줘서 해결.

728x90