Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
53aab246
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,体验更适合开发者的 AI 搜索 >>
提交
53aab246
编写于
2月 09, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
74ad2081
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
15 addition
and
25 deletion
+15
-25
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java
...mework/context/annotation/ConfigurationClassEnhancer.java
+7
-2
spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJacksonJsonView.java
...amework/web/servlet/view/json/MappingJacksonJsonView.java
+1
-1
spring-webmvc/src/test/java/org/springframework/web/servlet/view/json/MappingJacksonJsonViewTests.java
...rk/web/servlet/view/json/MappingJacksonJsonViewTests.java
+7
-22
未找到文件。
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java
浏览文件 @
53aab246
...
...
@@ -48,8 +48,13 @@ import org.springframework.util.Assert;
import
org.springframework.util.ReflectionUtils
;
/**
* Enhances {@link Configuration} classes by generating a CGLIB subclass capable of
* interacting with the Spring container to respect bean semantics.
* Enhances {@link Configuration} classes by generating a CGLIB subclass which
* interacts with the Spring container to respect bean scoping semantics for
* {@code @Bean} methods. Each such {@code @Bean} method will be overridden in
* the generated subclass, only delegating to the actual {@code @Bean} method
* implementation if the container actually requests the construction of a new
* instance. Otherwise, a call to such an {@code @Bean} method serves as a
* reference back to the container, obtaining the corresponding bean by name.
*
* @author Chris Beams
* @author Juergen Hoeller
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJacksonJsonView.java
浏览文件 @
53aab246
...
...
@@ -39,7 +39,7 @@ import org.springframework.web.servlet.view.AbstractView;
/**
* Spring MVC {@link View} that renders JSON content by serializing the model for the current request
* using <a href="http://jackson.codehaus.org/">Jackson's</a> {@link ObjectMapper}.
* using <a href="http://jackson.codehaus.org/">Jackson
1.x
's</a> {@link ObjectMapper}.
*
* <p>By default, the entire contents of the model map (with the exception of framework-specific classes)
* will be encoded as JSON. If the model contains only one key, you can have it extracted encoded as JSON
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/view/json/MappingJacksonJsonViewTests.java
浏览文件 @
53aab246
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
4
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.
...
...
@@ -39,6 +39,7 @@ import org.junit.Test;
import
org.mozilla.javascript.Context
;
import
org.mozilla.javascript.ContextFactory
;
import
org.mozilla.javascript.ScriptableObject
;
import
org.springframework.mock.web.test.MockHttpServletRequest
;
import
org.springframework.mock.web.test.MockHttpServletResponse
;
import
org.springframework.ui.ModelMap
;
...
...
@@ -68,10 +69,8 @@ public class MappingJacksonJsonViewTests {
public
void
setUp
()
{
request
=
new
MockHttpServletRequest
();
response
=
new
MockHttpServletResponse
();
jsContext
=
ContextFactory
.
getGlobal
().
enterContext
();
jsScope
=
jsContext
.
initStandardObjects
();
view
=
new
MappingJacksonJsonView
();
}
...
...
@@ -93,13 +92,11 @@ public class MappingJacksonJsonViewTests {
assertEquals
(
"no-cache"
,
response
.
getHeader
(
"Pragma"
));
assertEquals
(
"no-cache, no-store, max-age=0"
,
response
.
getHeader
(
"Cache-Control"
));
assertNotNull
(
response
.
getHeader
(
"Expires"
));
assertEquals
(
MappingJacksonJsonView
.
DEFAULT_CONTENT_TYPE
,
response
.
getContentType
());
String
jsonResult
=
response
.
getContentAsString
();
assertTrue
(
jsonResult
.
length
()
>
0
);
assertEquals
(
jsonResult
.
length
(),
response
.
getContentLength
());
validateResult
();
}
...
...
@@ -110,7 +107,6 @@ public class MappingJacksonJsonViewTests {
Map
<
String
,
Object
>
model
=
new
HashMap
<
String
,
Object
>();
model
.
put
(
"bindingResult"
,
mock
(
BindingResult
.
class
,
"binding_result"
));
model
.
put
(
"foo"
,
"bar"
);
view
.
render
(
model
,
request
,
response
);
assertNull
(
response
.
getHeader
(
"Pragma"
));
...
...
@@ -130,26 +126,22 @@ public class MappingJacksonJsonViewTests {
Map
<
String
,
Object
>
model
=
new
HashMap
<
String
,
Object
>();
model
.
put
(
"bindingResult"
,
mock
(
BindingResult
.
class
,
"binding_result"
));
model
.
put
(
"foo"
,
bean
);
view
.
setUpdateContentLength
(
true
);
view
.
render
(
model
,
request
,
response
);
assertTrue
(
response
.
getContentAsString
().
length
()
>
0
);
assertEquals
(
response
.
getContentAsString
().
length
(),
response
.
getContentLength
());
validateResult
();
}
@Test
public
void
renderWithPrettyPrint
()
throws
Exception
{
ModelMap
model
=
new
ModelMap
(
"foo"
,
new
TestBeanSimple
());
view
.
setPrettyPrint
(
true
);
view
.
render
(
model
,
request
,
response
);
String
result
=
response
.
getContentAsString
().
replace
(
"\r\n"
,
"\n"
);
assertTrue
(
"Pretty printing not applied:\n"
+
result
,
result
.
startsWith
(
"{\n \"foo\" : {\n "
));
validateResult
();
}
...
...
@@ -172,12 +164,10 @@ public class MappingJacksonJsonViewTests {
Object
bean
=
new
TestBeanSimpleAnnotated
();
Map
<
String
,
Object
>
model
=
new
HashMap
<
String
,
Object
>();
model
.
put
(
"foo"
,
bean
);
view
.
render
(
model
,
request
,
response
);
assertTrue
(
response
.
getContentAsString
().
length
()
>
0
);
assertEquals
(
"{\"foo\":{\"testBeanSimple\":\"custom\"}}"
,
response
.
getContentAsString
());
validateResult
();
}
...
...
@@ -192,13 +182,11 @@ public class MappingJacksonJsonViewTests {
Map
<
String
,
Object
>
model
=
new
HashMap
<
String
,
Object
>();
model
.
put
(
"foo"
,
bean
);
model
.
put
(
"bar"
,
new
TestChildBean
());
view
.
render
(
model
,
request
,
response
);
String
result
=
response
.
getContentAsString
();
assertTrue
(
result
.
length
()
>
0
);
assertTrue
(
result
.
contains
(
"\"foo\":{\"testBeanSimple\":\"custom\"}"
));
validateResult
();
}
...
...
@@ -214,14 +202,12 @@ public class MappingJacksonJsonViewTests {
model
.
put
(
"foo"
,
"foo"
);
model
.
put
(
"bar"
,
"bar"
);
model
.
put
(
"baz"
,
"baz"
);
view
.
render
(
model
,
request
,
response
);
String
result
=
response
.
getContentAsString
();
assertTrue
(
result
.
length
()
>
0
);
assertTrue
(
result
.
contains
(
"\"foo\":\"foo\""
));
assertTrue
(
result
.
contains
(
"\"baz\":\"baz\""
));
validateResult
();
}
...
...
@@ -232,7 +218,6 @@ public class MappingJacksonJsonViewTests {
Map
<
String
,
Object
>
model
=
new
HashMap
<
String
,
Object
>();
TestBeanSimple
bean
=
new
TestBeanSimple
();
model
.
put
(
"foo"
,
bean
);
Object
actual
=
view
.
filterModel
(
model
);
assertSame
(
bean
,
actual
);
...
...
@@ -295,7 +280,7 @@ public class MappingJacksonJsonViewTests {
}
@JsonSerialize
(
using
=
TestBeanSimpleSerializer
.
class
)
@JsonSerialize
(
using
=
TestBeanSimpleSerializer
.
class
)
public
static
class
TestBeanSimpleAnnotated
extends
TestBeanSimple
{
}
...
...
@@ -329,9 +314,7 @@ public class MappingJacksonJsonViewTests {
public
static
class
TestBeanSimpleSerializer
extends
JsonSerializer
<
Object
>
{
@Override
public
void
serialize
(
Object
value
,
JsonGenerator
jgen
,
SerializerProvider
provider
)
throws
IOException
{
public
void
serialize
(
Object
value
,
JsonGenerator
jgen
,
SerializerProvider
provider
)
throws
IOException
{
jgen
.
writeStartObject
();
jgen
.
writeFieldName
(
"testBeanSimple"
);
jgen
.
writeString
(
"custom"
);
...
...
@@ -348,7 +331,9 @@ public class MappingJacksonJsonViewTests {
}
@Override
public
JsonSerializer
<
Object
>
createSerializer
(
SerializationConfig
config
,
JavaType
baseType
,
BeanProperty
property
)
throws
JsonMappingException
{
public
JsonSerializer
<
Object
>
createSerializer
(
SerializationConfig
config
,
JavaType
baseType
,
BeanProperty
property
)
throws
JsonMappingException
{
if
(
baseType
.
getRawClass
()
==
TestBeanSimple
.
class
)
{
return
new
TestBeanSimpleSerializer
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录