Restore original JsonMappingException handling (assuming invalid input)
Closes gh-24610 Closes gh-24630 Closes gh-24646
This commit is contained in:
parent
988aae4f2e
commit
6df80a8f70
|
|
@ -25,11 +25,9 @@ import java.util.Map;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectReader;
|
||||
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
|
||||
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
|
||||
import com.fasterxml.jackson.databind.util.TokenBuffer;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
|
@ -208,18 +206,10 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
|
|||
}
|
||||
|
||||
private CodecException processException(IOException ex) {
|
||||
if (ex instanceof MismatchedInputException) { // specific kind of JsonMappingException
|
||||
String originalMessage = ((MismatchedInputException) ex).getOriginalMessage();
|
||||
return new DecodingException("Invalid JSON input: " + originalMessage, ex);
|
||||
}
|
||||
if (ex instanceof InvalidDefinitionException) { // another kind of JsonMappingException
|
||||
if (ex instanceof InvalidDefinitionException) {
|
||||
JavaType type = ((InvalidDefinitionException) ex).getType();
|
||||
return new CodecException("Type definition error: " + type, ex);
|
||||
}
|
||||
if (ex instanceof JsonMappingException) { // typically ValueInstantiationException
|
||||
String originalMessage = ((JsonMappingException) ex).getOriginalMessage();
|
||||
return new CodecException("JSON conversion problem: " + originalMessage, ex);
|
||||
}
|
||||
if (ex instanceof JsonProcessingException) {
|
||||
String originalMessage = ((JsonProcessingException) ex).getOriginalMessage();
|
||||
return new DecodingException("JSON decoding error: " + originalMessage, ex);
|
||||
|
|
|
|||
|
|
@ -30,12 +30,10 @@ import com.fasterxml.jackson.core.JsonGenerator;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import com.fasterxml.jackson.databind.SequenceWriter;
|
||||
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
|
||||
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
|
@ -72,7 +70,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
|||
private static final Map<MediaType, byte[]> STREAM_SEPARATORS;
|
||||
|
||||
static {
|
||||
STREAM_SEPARATORS = new HashMap<>();
|
||||
STREAM_SEPARATORS = new HashMap<>(4);
|
||||
STREAM_SEPARATORS.put(MediaType.APPLICATION_STREAM_JSON, NEWLINE_SEPARATOR);
|
||||
STREAM_SEPARATORS.put(MediaType.parseMediaType("application/stream+x-jackson-smile"), new byte[0]);
|
||||
}
|
||||
|
|
@ -166,15 +164,9 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
|||
writer.writeValue(generator, value);
|
||||
generator.flush();
|
||||
}
|
||||
catch (MismatchedInputException ex) { // specific kind of JsonMappingException
|
||||
throw new EncodingException("Invalid JSON input: " + ex.getOriginalMessage(), ex);
|
||||
}
|
||||
catch (InvalidDefinitionException ex) { // another kind of JsonMappingException
|
||||
catch (InvalidDefinitionException ex) {
|
||||
throw new CodecException("Type definition error: " + ex.getType(), ex);
|
||||
}
|
||||
catch (JsonMappingException ex) { // typically ValueInstantiationException
|
||||
throw new CodecException("JSON conversion problem: " + ex.getOriginalMessage(), ex);
|
||||
}
|
||||
catch (JsonProcessingException ex) {
|
||||
throw new EncodingException("JSON encoding error: " + ex.getOriginalMessage(), ex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ import com.fasterxml.jackson.databind.ObjectWriter;
|
|||
import com.fasterxml.jackson.databind.SerializationConfig;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
|
||||
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
|
||||
import com.fasterxml.jackson.databind.ser.FilterProvider;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
|
||||
|
|
@ -239,15 +238,9 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
|||
}
|
||||
return this.objectMapper.readValue(inputMessage.getBody(), javaType);
|
||||
}
|
||||
catch (MismatchedInputException ex) { // specific kind of JsonMappingException
|
||||
throw new HttpMessageNotReadableException("Invalid JSON input: " + ex.getOriginalMessage(), ex, inputMessage);
|
||||
}
|
||||
catch (InvalidDefinitionException ex) { // another kind of JsonMappingException
|
||||
catch (InvalidDefinitionException ex) {
|
||||
throw new HttpMessageConversionException("Type definition error: " + ex.getType(), ex);
|
||||
}
|
||||
catch (JsonMappingException ex) { // typically ValueInstantiationException
|
||||
throw new HttpMessageConversionException("JSON conversion problem: " + ex.getOriginalMessage(), ex);
|
||||
}
|
||||
catch (JsonProcessingException ex) {
|
||||
throw new HttpMessageNotReadableException("JSON parse error: " + ex.getOriginalMessage(), ex, inputMessage);
|
||||
}
|
||||
|
|
@ -296,15 +289,9 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
|||
writeSuffix(generator, object);
|
||||
generator.flush();
|
||||
}
|
||||
catch (MismatchedInputException ex) { // specific kind of JsonMappingException
|
||||
throw new HttpMessageNotWritableException("Invalid JSON input: " + ex.getOriginalMessage(), ex);
|
||||
}
|
||||
catch (InvalidDefinitionException ex) { // another kind of JsonMappingException
|
||||
catch (InvalidDefinitionException ex) {
|
||||
throw new HttpMessageConversionException("Type definition error: " + ex.getType(), ex);
|
||||
}
|
||||
catch (JsonMappingException ex) { // typically ValueInstantiationException
|
||||
throw new HttpMessageConversionException("JSON mapping problem: " + ex.getPathReference(), ex);
|
||||
}
|
||||
catch (JsonProcessingException ex) {
|
||||
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getOriginalMessage(), ex);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue