728x90
반응형

1. ajax으로 json 형태의 데이터를 보낼때 

에러 : org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

javascript 소스의 ajax에 contentType: 'application/json' 추가

 

2. javascript ajax에서 form의 데이터를 json으로 보내야 할때

에러 : org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized token 'page': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'page': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')

 

JavaScript Ajax JSON parse error

Spring Controller와 통신하는 Ajax JSON parse error 고치기!

velog.io

 

jquery form serialize 를 이용하여 json으로 만들기

jquery 에서 form serialize를 이용하여 json 을 만들수 있습니다. 먼저 serialize 에 대해서 간단히 설명하겠습니다. serialize 함수는 2개가 있습니다. 첫번째로 serialize() 입니다. URL-encoded 표기법으로 fo..

cofs.tistory.com

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
 * form 데이터를 json으로 변환
* 사용방법 : JSON.stringify( $("#WRITE_FORM").serializeObject())
 * 출처: https://cofs.tistory.com/184 [CofS]
 */
jQuery.fn.serializeObject = function() {
    var obj = null;
    try {
        if (this[0].tagName && this[0].tagName.toUpperCase() == "FORM") {
            var arr = this.serializeArray();
            if (arr) {
                obj = {};
                jQuery.each(arr, function() {
                    obj[this.name= this.value;
                });
            }//if ( arr ) {
        }
    } catch (e) {
        alert(e.message);
    } finally {
    }
 
    return obj;
};
 
cs

 

3. spring boot에서 리턴 할때 발생한 에러

에러 : HttpMessageNotWritableException: No converter for with preset Content-Type 'null'

 

HttpMessageNotWritableException: No converter for [VO Class] with preset Content-Type 'null'] | ThinkGround

안녕하세요. No converter for [VO Class] with preset Content-Type 'null'] 오류와 관련된 해결 포스트입니다. Spring은 기본적으로 MessageConvertor가 탑재되어 있습니다.

thinkground.studio

위 링크의 정보를 참고해서 리턴 class에 @JsonInclude(JsonInclude.Include.NON_NULL) 를 추가하고 해결됐다.

에러 메시지를 메모해 두기 위해 다시 소스를 원상복구 후 실행 했을때는 에러가 나지는 않았다. ㅡㅡ?? 응??

현재는 위 내용을 제거하고 실행하고 있지만 에러가 없는 상태.

 

 

4. 파일을 전송하기 위한 ajax에서 발생

에러 : java.lang.IllegalStateException: Current request is not of type [org.springframework.web.multipart.MultipartHttpServletRequest]: ServletWebRequest: uri=/bbs/ajax/insert;client=0:0:0:0:0:0:0:1;session=01C5D81F89E59ACA7C2BEE397A35A677

 

ajax 호출을 받는 controller에서 MultipartHttpServletRequest가 누락된 경우 발생한다.

 

728x90
반응형

+ Recent posts