Polishing

This commit is contained in:
Juergen Hoeller
2014-08-18 19:27:08 +02:00
parent 0d0d7139ee
commit 2ef3d66c89
6 changed files with 94 additions and 97 deletions

View File

@@ -53,8 +53,8 @@ import org.springframework.util.ClassUtils;
* @author Sebastien Deleuze
* @since 4.1
*/
public abstract class AbstractJackson2HttpMessageConverter extends
AbstractHttpMessageConverter<Object> implements GenericHttpMessageConverter<Object> {
public abstract class AbstractJackson2HttpMessageConverter extends AbstractHttpMessageConverter<Object>
implements GenericHttpMessageConverter<Object> {
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
@@ -82,6 +82,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends
this.objectMapper = objectMapper;
}
/**
* Set the {@code ObjectMapper} for this view.
* If not set, a default {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.
@@ -126,6 +127,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends
}
}
@Override
public boolean canRead(Class<?> clazz, MediaType mediaType) {
return canRead(clazz, null, mediaType);

View File

@@ -54,6 +54,7 @@ public class MappingJackson2HttpMessageConverter extends AbstractJackson2HttpMes
new MediaType("application", "*+json", DEFAULT_CHARSET));
}
/**
* Specify a custom prefix to use for this view's JSON output.
* Default is none.
@@ -75,15 +76,14 @@ public class MappingJackson2HttpMessageConverter extends AbstractJackson2HttpMes
this.jsonPrefix = (prefixJson ? "{} && " : null);
}
@Override
protected void writePrefix(JsonGenerator generator, Object object) throws IOException {
if (this.jsonPrefix != null) {
generator.writeRaw(this.jsonPrefix);
}
String jsonpFunction = null;
if (object instanceof MappingJacksonValue) {
jsonpFunction = ((MappingJacksonValue)object).getJsonpFunction();
}
String jsonpFunction =
(object instanceof MappingJacksonValue ? ((MappingJacksonValue) object).getJsonpFunction() : null);
if (jsonpFunction != null) {
generator.writeRaw(jsonpFunction + "(");
}
@@ -91,10 +91,8 @@ public class MappingJackson2HttpMessageConverter extends AbstractJackson2HttpMes
@Override
protected void writeSuffix(JsonGenerator generator, Object object) throws IOException {
String jsonpFunction = null;
if (object instanceof MappingJacksonValue) {
jsonpFunction = ((MappingJacksonValue)object).getJsonpFunction();
}
String jsonpFunction =
(object instanceof MappingJacksonValue ? ((MappingJacksonValue) object).getJsonpFunction() : null);
if (jsonpFunction != null) {
generator.writeRaw(");");
}

View File

@@ -20,12 +20,11 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
/**
* Implementation of {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverter} that
* can read and write XML using <a href="https://github.com/FasterXML/jackson-dataformat-xml">Jackson 2.x extension component for
* reading and writing XML encoded data</a>.
* Implementation of {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverter}
* that can read and write XML using <a href="https://github.com/FasterXML/jackson-dataformat-xml">
* Jackson 2.x extension component for reading and writing XML encoded data</a>.
*
* @author Sebastien Deleuze
* @since 4.1
@@ -33,8 +32,7 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
public class MappingJackson2XmlHttpMessageConverter extends AbstractJackson2HttpMessageConverter {
public MappingJackson2XmlHttpMessageConverter() {
super(new XmlMapper(),
new MediaType("application", "xml", MappingJackson2HttpMessageConverter.DEFAULT_CHARSET));
super(new XmlMapper(), new MediaType("application", "xml", DEFAULT_CHARSET));
}
}