From d1241e18dea6ea5949d001bc349c22963483f31d Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 15 Sep 2020 10:22:46 +0200 Subject: [PATCH] Polishing (cherry picked from commit f010368a66cd15b6bd6b54b0f2b9d7ea3433c30a) --- .../beans/propertyeditors/URIEditor.java | 4 ++-- .../json/AbstractJackson2HttpMessageConverter.java | 10 +++++----- .../json/AbstractJsonHttpMessageConverter.java | 13 ++++++++----- .../converter/json/GsonHttpMessageConverter.java | 8 ++++---- .../converter/json/JsonbHttpMessageConverter.java | 8 ++++---- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/URIEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/URIEditor.java index 8327653c456..344fb5d439f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/URIEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/URIEditor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -119,7 +119,7 @@ public class URIEditor extends PropertyEditorSupport { setValue(createURI(uri)); } catch (URISyntaxException ex) { - throw new IllegalArgumentException("Invalid URI syntax: " + ex); + throw new IllegalArgumentException("Invalid URI syntax: " + ex.getMessage()); } } } diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java index e062fe193a3..7e4527c7e27 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -210,18 +210,18 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener } @Override - protected Object readInternal(Class clazz, HttpInputMessage inputMessage) + public Object read(Type type, @Nullable Class contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { - JavaType javaType = getJavaType(clazz, null); + JavaType javaType = getJavaType(type, contextClass); return readJavaType(javaType, inputMessage); } @Override - public Object read(Type type, @Nullable Class contextClass, HttpInputMessage inputMessage) + protected Object readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { - JavaType javaType = getJavaType(type, contextClass); + JavaType javaType = getJavaType(clazz, null); return readJavaType(javaType, inputMessage); } diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJsonHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJsonHttpMessageConverter.java index 0783fa96ad8..22b4c5c8285 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJsonHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJsonHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,6 +50,9 @@ import org.springframework.lang.Nullable; */ public abstract class AbstractJsonHttpMessageConverter extends AbstractGenericHttpMessageConverter { + /** + * The default charset used by the converter. + */ public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; @Nullable @@ -111,7 +114,7 @@ public abstract class AbstractJsonHttpMessageConverter extends AbstractGenericHt } @Override - protected final void writeInternal(Object o, @Nullable Type type, HttpOutputMessage outputMessage) + protected final void writeInternal(Object object, @Nullable Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { Writer writer = getWriter(outputMessage); @@ -119,7 +122,7 @@ public abstract class AbstractJsonHttpMessageConverter extends AbstractGenericHt writer.append(this.jsonPrefix); } try { - writeInternal(o, type, writer); + writeInternal(object, type, writer); } catch (Exception ex) { throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex); @@ -139,12 +142,12 @@ public abstract class AbstractJsonHttpMessageConverter extends AbstractGenericHt /** * Template method that writes the JSON-bound object to the given {@link Writer}. - * @param o the object to write to the output message + * @param object the object to write to the output message * @param type the type of object to write (may be {@code null}) * @param writer the {@code} Writer to use * @throws Exception in case of write failures */ - protected abstract void writeInternal(Object o, @Nullable Type type, Writer writer) throws Exception; + protected abstract void writeInternal(Object object, @Nullable Type type, Writer writer) throws Exception; private static Reader getReader(HttpInputMessage inputMessage) throws IOException { diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java index b054cf46668..8c363b4eae1 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,17 +93,17 @@ public class GsonHttpMessageConverter extends AbstractJsonHttpMessageConverter { } @Override - protected void writeInternal(Object o, @Nullable Type type, Writer writer) throws Exception { + protected void writeInternal(Object object, @Nullable Type type, Writer writer) throws Exception { // In Gson, toJson with a type argument will exclusively use that given type, // ignoring the actual type of the object... which might be more specific, // e.g. a subclass of the specified type which includes additional fields. // As a consequence, we're only passing in parameterized type declarations // which might contain extra generics that the object instance doesn't retain. if (type instanceof ParameterizedType) { - getGson().toJson(o, type, writer); + getGson().toJson(object, type, writer); } else { - getGson().toJson(o, writer); + getGson().toJson(object, writer); } } diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/JsonbHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/JsonbHttpMessageConverter.java index 7e63273eaf6..a3272669971 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/JsonbHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/JsonbHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -100,12 +100,12 @@ public class JsonbHttpMessageConverter extends AbstractJsonHttpMessageConverter } @Override - protected void writeInternal(Object o, @Nullable Type type, Writer writer) throws Exception { + protected void writeInternal(Object object, @Nullable Type type, Writer writer) throws Exception { if (type instanceof ParameterizedType) { - getJsonb().toJson(o, type, writer); + getJsonb().toJson(object, type, writer); } else { - getJsonb().toJson(o, writer); + getJsonb().toJson(object, writer); } }