Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
951c664c
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
951c664c
编写于
6月 24, 2009
作者:
A
Arjen Poutsma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removed JsonFactory property, which is redundant with the ObjectMapper property.
上级
f1b93651
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
6 addition
and
18 deletion
+6
-18
org.springframework.web/src/main/java/org/springframework/http/converter/json/BindingJacksonHttpMessageConverter.java
...tp/converter/json/BindingJacksonHttpMessageConverter.java
+6
-18
未找到文件。
org.springframework.web/src/main/java/org/springframework/http/converter/json/BindingJacksonHttpMessageConverter.java
浏览文件 @
951c664c
...
...
@@ -21,9 +21,7 @@ import java.nio.charset.Charset;
import
java.util.List
;
import
org.codehaus.jackson.JsonEncoding
;
import
org.codehaus.jackson.JsonFactory
;
import
org.codehaus.jackson.JsonGenerator
;
import
org.codehaus.jackson.map.MappingJsonFactory
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.springframework.http.HttpInputMessage
;
...
...
@@ -38,7 +36,7 @@ import org.springframework.util.Assert;
* Implementation of {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverter} that can read
* and write JSON using <a href="http://jackson.codehaus.org/">Jackson's</a> {@link ObjectMapper}.
*
* <p>This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances.
* <p>This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances.
*
* <p>By default, this converter supports {@code application/json}. This can be overridden by setting the {@link
* #setSupportedMediaTypes(List) supportedMediaTypes} property, and overriding the {@link #getContentType(Object)}
...
...
@@ -51,13 +49,9 @@ public class BindingJacksonHttpMessageConverter<T> extends AbstractHttpMessageCo
private
ObjectMapper
objectMapper
=
new
ObjectMapper
();
private
JsonFactory
jsonFactory
=
new
MappingJsonFactory
();
private
JsonEncoding
encoding
=
JsonEncoding
.
UTF8
;
/**
* Construct a new {@code BindingJacksonHttpMessageConverter},
*/
/** Construct a new {@code BindingJacksonHttpMessageConverter}, */
public
BindingJacksonHttpMessageConverter
()
{
super
(
new
MediaType
(
"application"
,
"json"
));
}
...
...
@@ -71,16 +65,9 @@ public class BindingJacksonHttpMessageConverter<T> extends AbstractHttpMessageCo
this
.
objectMapper
=
objectMapper
;
}
/** Sets the {@code JsonFactory} for this converter. By default, a {@link MappingJsonFactory} is used. */
public
void
setJsonFactory
(
JsonFactory
jsonFactory
)
{
Assert
.
notNull
(
jsonFactory
,
"'jsonFactory' must not be null"
);
this
.
jsonFactory
=
jsonFactory
;
}
/**
* Sets the {@code JsonEncoding} for this converter. By default, {@linkplain JsonEncoding#UTF8 UTF-8} is used.
*/
/** Sets the {@code JsonEncoding} for this converter. By default, {@linkplain JsonEncoding#UTF8 UTF-8} is used. */
public
void
setEncoding
(
JsonEncoding
encoding
)
{
Assert
.
notNull
(
encoding
,
"'encoding' must not be null"
);
this
.
encoding
=
encoding
;
}
...
...
@@ -103,7 +90,8 @@ public class BindingJacksonHttpMessageConverter<T> extends AbstractHttpMessageCo
@Override
protected
void
writeInternal
(
T
t
,
HttpOutputMessage
outputMessage
)
throws
IOException
,
HttpMessageNotWritableException
{
JsonGenerator
jsonGenerator
=
jsonFactory
.
createJsonGenerator
(
outputMessage
.
getBody
(),
encoding
);
JsonGenerator
jsonGenerator
=
objectMapper
.
getJsonFactory
().
createJsonGenerator
(
outputMessage
.
getBody
(),
encoding
);
objectMapper
.
writeValue
(
jsonGenerator
,
t
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录