org.springframework.core.codec.DecodingException: ข้อผิดพลาดในการถอดรหัส JSON: อักขระที่ไม่ถูกต้อง ((CTRL-CHAR, รหัส 31))
ฉันได้รับข้อผิดพลาดต่อไปนี้ในการตอบสนองของวิธีการโพสต์ผ่าน WebClient (org.springframework.web.reactive.function.client)
org.springframework.core.codec.DecodingException: JSON decoding error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens
at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 2]
at org.springframework.http.codec.json.AbstractJackson2Decoder.processException(AbstractJackson2Decoder.java:215)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Ȁ
ฉันได้ลองเปลี่ยนส่วนหัวของคำขอแล้วโดยล้มเหลว : -
headers.put("Accept-Encoding", "gzip");
หรือ
headers.put("Accept-Encoding", "identity");
Webclient ไม่สามารถประมวลผลการตอบกลับแบบ gzipped ได้ด้วยเหตุผลใดก็ตาม !!
ขอบคุณล่วงหน้า!!
คำตอบ
ฉันพลาดการใช้ Serializable กับวัตถุตอบสนอง
ฉันได้เริ่มได้รับข้อยกเว้นนี้ด้วยการพึ่งพา feign ของ Spring boot spring-cloud-openfeign-coreเมื่อฉันอัปเกรดเวอร์ชันspring-cloud-openfeign-coreเป็น2.2.5.RELEASE.
สำหรับผู้ที่อัปเกรดเป็นเวอร์ชัน 2.2.5 รีลีสหรือเวอร์ชันที่ใหม่กว่าจะประสบปัญหานี้หากมีคุณสมบัติfeign.request.compression=trueอยู่แล้ว
เหตุผลทางเทคนิคที่อยู่เบื้องหลังสิ่งนี้คือใน
FeignContentGzipEncodingAutoConfigurationชั้นเรียนลายเซ็นคำอธิบายประกอบคุณสมบัติตามเงื่อนไขเปลี่ยนจาก@ConditionalOnProperty("feign.compression.request.enabled", matchIfMissing = false)เป็น@ConditionalOnProperty(value = "feign.compression.request.enabled")ดังนั้นโดยค่าเริ่มต้นFeignContentGzipEncodingInterceptorจะถูกทริกเกอร์ ข้อมูลอ้างอิง GitHub
วิธีแก้ปัญหา
หากคุณเรียกใช้บริการสปริงบูตซึ่งไม่มีกลไกในการจัดการให้compressed requestปิดใช้งานการบีบอัดคำขอปลอมโดยใช้คุณสมบัติด้านล่าง
feign.request.compression=false.
หมายเหตุ : น่าเสียดายที่เรายังไม่มีโซลูชันสำเร็จรูปในสปริงบูตเพื่อจัดการการอ้างอิงคำขอบีบอัด