Polishing
This commit is contained in:
parent
3ec4538981
commit
f010368a66
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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));
|
setValue(createURI(uri));
|
||||||
}
|
}
|
||||||
catch (URISyntaxException ex) {
|
catch (URISyntaxException ex) {
|
||||||
throw new IllegalArgumentException("Invalid URI syntax: " + ex);
|
throw new IllegalArgumentException("Invalid URI syntax: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,14 +234,6 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage)
|
|
||||||
throws IOException, HttpMessageNotReadableException {
|
|
||||||
|
|
||||||
JavaType javaType = getJavaType(clazz, null);
|
|
||||||
return readJavaType(javaType, inputMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object read(Type type, @Nullable Class<?> contextClass, HttpInputMessage inputMessage)
|
public Object read(Type type, @Nullable Class<?> contextClass, HttpInputMessage inputMessage)
|
||||||
throws IOException, HttpMessageNotReadableException {
|
throws IOException, HttpMessageNotReadableException {
|
||||||
|
@ -250,6 +242,14 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||||
return readJavaType(javaType, inputMessage);
|
return readJavaType(javaType, inputMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage)
|
||||||
|
throws IOException, HttpMessageNotReadableException {
|
||||||
|
|
||||||
|
JavaType javaType = getJavaType(clazz, null);
|
||||||
|
return readJavaType(javaType, inputMessage);
|
||||||
|
}
|
||||||
|
|
||||||
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) throws IOException {
|
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) throws IOException {
|
||||||
MediaType contentType = inputMessage.getHeaders().getContentType();
|
MediaType contentType = inputMessage.getHeaders().getContentType();
|
||||||
Charset charset = getCharset(contentType);
|
Charset charset = getCharset(contentType);
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -114,7 +114,7 @@ public abstract class AbstractJsonHttpMessageConverter extends AbstractGenericHt
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 {
|
throws IOException, HttpMessageNotWritableException {
|
||||||
|
|
||||||
Writer writer = getWriter(outputMessage);
|
Writer writer = getWriter(outputMessage);
|
||||||
|
@ -122,7 +122,7 @@ public abstract class AbstractJsonHttpMessageConverter extends AbstractGenericHt
|
||||||
writer.append(this.jsonPrefix);
|
writer.append(this.jsonPrefix);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
writeInternal(o, type, writer);
|
writeInternal(object, type, writer);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
|
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
|
||||||
|
@ -142,12 +142,12 @@ public abstract class AbstractJsonHttpMessageConverter extends AbstractGenericHt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template method that writes the JSON-bound object to the given {@link Writer}.
|
* 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 type the type of object to write (may be {@code null})
|
||||||
* @param writer the {@code} Writer to use
|
* @param writer the {@code} Writer to use
|
||||||
* @throws Exception in case of write failures
|
* @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 {
|
private static Reader getReader(HttpInputMessage inputMessage) throws IOException {
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -93,17 +93,17 @@ public class GsonHttpMessageConverter extends AbstractJsonHttpMessageConverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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,
|
// 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,
|
// ignoring the actual type of the object... which might be more specific,
|
||||||
// e.g. a subclass of the specified type which includes additional fields.
|
// e.g. a subclass of the specified type which includes additional fields.
|
||||||
// As a consequence, we're only passing in parameterized type declarations
|
// As a consequence, we're only passing in parameterized type declarations
|
||||||
// which might contain extra generics that the object instance doesn't retain.
|
// which might contain extra generics that the object instance doesn't retain.
|
||||||
if (type instanceof ParameterizedType) {
|
if (type instanceof ParameterizedType) {
|
||||||
getGson().toJson(o, type, writer);
|
getGson().toJson(object, type, writer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getGson().toJson(o, writer);
|
getGson().toJson(object, writer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -101,12 +101,12 @@ public class JsonbHttpMessageConverter extends AbstractJsonHttpMessageConverter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
if (type instanceof ParameterizedType) {
|
||||||
getJsonb().toJson(o, type, writer);
|
getJsonb().toJson(object, type, writer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getJsonb().toJson(o, writer);
|
getJsonb().toJson(object, writer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue