Skip to content

Commit e66bc07

Browse files
committed
Translate EOF to HttpMessageNotReadableException
The MappingJacksonHttpMessageConverter now catches all IOException types raised while reading JSON and translates them into HttpMessageNotReadableException. Issue: SPR-9238 Backport-Issue: SPR-9397 Backport-Commit: 816c1f4
1 parent c9a2dbd commit e66bc07

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

build-spring-framework/resources/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Changes in version 3.1.2 (2012-06-??)
1717
* fixed StandardServletMultipartResolver compatibility with Resin (only deleting actual file parts)
1818
* fix issue with parsing invalid Content-Type or Accept headers
1919
* add Jackson 2 HttpMessageConverter and View types
20+
* translate IOException from Jackson to HttpMessageNotReadableException
2021

2122
Changes in version 3.1.1 (2012-02-16)
2223
-------------------------------------

org.springframework.web/src/main/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
import com.fasterxml.jackson.core.JsonEncoding;
3232
import com.fasterxml.jackson.core.JsonGenerator;
33-
import com.fasterxml.jackson.core.JsonProcessingException;
3433
import com.fasterxml.jackson.databind.JavaType;
3534
import com.fasterxml.jackson.databind.ObjectMapper;
3635

@@ -123,7 +122,7 @@ protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage)
123122
try {
124123
return this.objectMapper.readValue(inputMessage.getBody(), javaType);
125124
}
126-
catch (JsonProcessingException ex) {
125+
catch (IOException ex) {
127126
throw new HttpMessageNotReadableException("Could not read JSON: " + ex.getMessage(), ex);
128127
}
129128
}
@@ -141,7 +140,7 @@ protected void writeInternal(Object object, HttpOutputMessage outputMessage)
141140
}
142141
this.objectMapper.writeValue(jsonGenerator, object);
143142
}
144-
catch (JsonProcessingException ex) {
143+
catch (IOException ex) {
145144
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
146145
}
147146
}

org.springframework.web/src/main/java/org/springframework/http/converter/json/MappingJacksonHttpMessageConverter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222

2323
import org.codehaus.jackson.JsonEncoding;
2424
import org.codehaus.jackson.JsonGenerator;
25-
import org.codehaus.jackson.JsonProcessingException;
2625
import org.codehaus.jackson.map.ObjectMapper;
2726
import org.codehaus.jackson.map.type.TypeFactory;
2827
import org.codehaus.jackson.type.JavaType;
29-
3028
import org.springframework.http.HttpInputMessage;
3129
import org.springframework.http.HttpOutputMessage;
3230
import org.springframework.http.MediaType;
@@ -123,7 +121,7 @@ protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage)
123121
try {
124122
return this.objectMapper.readValue(inputMessage.getBody(), javaType);
125123
}
126-
catch (JsonProcessingException ex) {
124+
catch (IOException ex) {
127125
throw new HttpMessageNotReadableException("Could not read JSON: " + ex.getMessage(), ex);
128126
}
129127
}
@@ -141,7 +139,7 @@ protected void writeInternal(Object object, HttpOutputMessage outputMessage)
141139
}
142140
this.objectMapper.writeValue(jsonGenerator, object);
143141
}
144-
catch (JsonProcessingException ex) {
142+
catch (IOException ex) {
145143
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
146144
}
147145
}

0 commit comments

Comments
 (0)