Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
b2eae000
Commit
b2eae000
authored
Jan 11, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Make GsonAutoConfiguration align with JacksonAutoConfiguration"
Closes gh-11591
parent
50518514
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
4 deletions
+31
-4
GsonAutoConfigurationTests.java
...k/boot/autoconfigure/gson/GsonAutoConfigurationTests.java
+31
-4
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfigurationTests.java
View file @
b2eae000
...
@@ -25,6 +25,7 @@ import com.google.gson.ExclusionStrategy;
...
@@ -25,6 +25,7 @@ import com.google.gson.ExclusionStrategy;
import
com.google.gson.FieldAttributes
;
import
com.google.gson.FieldAttributes
;
import
com.google.gson.FieldNamingPolicy
;
import
com.google.gson.FieldNamingPolicy
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.LongSerializationPolicy
;
import
com.google.gson.LongSerializationPolicy
;
import
org.joda.time.DateTime
;
import
org.joda.time.DateTime
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -32,6 +33,7 @@ import org.junit.Test;
...
@@ -32,6 +33,7 @@ import org.junit.Test;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -40,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -40,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
*
* @author David Liu
* @author David Liu
* @author Ivan Golovko
* @author Ivan Golovko
* @author Stephane Nicoll
*/
*/
public
class
GsonAutoConfigurationTests
{
public
class
GsonAutoConfigurationTests
{
...
@@ -146,13 +149,23 @@ public class GsonAutoConfigurationTests {
...
@@ -146,13 +149,23 @@ public class GsonAutoConfigurationTests {
@Test
@Test
public
void
additionalGsonBuilderCustomization
()
{
public
void
additionalGsonBuilderCustomization
()
{
this
.
contextRunner
.
withUserConfiguration
(
GsonBuilderCustomConfig
.
class
)
this
.
contextRunner
.
withUserConfiguration
(
GsonBuilderCustom
izer
Config
.
class
)
.
run
(
context
->
{
.
run
(
context
->
{
Gson
gson
=
context
.
getBean
(
Gson
.
class
);
Gson
gson
=
context
.
getBean
(
Gson
.
class
);
assertThat
(
gson
.
toJson
(
new
DataObject
())).
isEqualTo
(
"{}"
);
assertThat
(
gson
.
toJson
(
new
DataObject
())).
isEqualTo
(
"{}"
);
});
});
}
}
@Test
public
void
customGsonBuilder
()
{
this
.
contextRunner
.
withUserConfiguration
(
GsonBuilderConfig
.
class
)
.
run
(
context
->
{
Gson
gson
=
context
.
getBean
(
Gson
.
class
);
assertThat
(
gson
.
toJson
(
new
DataObject
()))
.
isEqualTo
(
"{\"data\":1,\"owner\":null}"
);
});
}
@Test
@Test
public
void
withPrettyPrinting
()
{
public
void
withPrettyPrinting
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.gson.pretty-printing:true"
)
this
.
contextRunner
.
withPropertyValues
(
"spring.gson.pretty-printing:true"
)
...
@@ -164,7 +177,7 @@ public class GsonAutoConfigurationTests {
...
@@ -164,7 +177,7 @@ public class GsonAutoConfigurationTests {
}
}
@Test
@Test
public
void
withoutLenient
()
throws
Exception
{
public
void
withoutLenient
()
{
this
.
contextRunner
.
run
(
context
->
{
this
.
contextRunner
.
run
(
context
->
{
Gson
gson
=
context
.
getBean
(
Gson
.
class
);
Gson
gson
=
context
.
getBean
(
Gson
.
class
);
/*
/*
...
@@ -180,7 +193,7 @@ public class GsonAutoConfigurationTests {
...
@@ -180,7 +193,7 @@ public class GsonAutoConfigurationTests {
}
}
@Test
@Test
public
void
withLenient
()
throws
Exception
{
public
void
withLenient
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.gson.lenient:true"
).
run
(
context
->
{
this
.
contextRunner
.
withPropertyValues
(
"spring.gson.lenient:true"
).
run
(
context
->
{
Gson
gson
=
context
.
getBean
(
Gson
.
class
);
Gson
gson
=
context
.
getBean
(
Gson
.
class
);
...
@@ -225,7 +238,8 @@ public class GsonAutoConfigurationTests {
...
@@ -225,7 +238,8 @@ public class GsonAutoConfigurationTests {
});
});
}
}
protected
static
class
GsonBuilderCustomConfig
{
@Configuration
static
class
GsonBuilderCustomizerConfig
{
@Bean
@Bean
public
GsonBuilderCustomizer
customSerializationExclusionStrategy
()
{
public
GsonBuilderCustomizer
customSerializationExclusionStrategy
()
{
...
@@ -245,6 +259,16 @@ public class GsonAutoConfigurationTests {
...
@@ -245,6 +259,16 @@ public class GsonAutoConfigurationTests {
}
}
@Configuration
static
class
GsonBuilderConfig
{
@Bean
public
GsonBuilder
customGsonBuilder
()
{
return
new
GsonBuilder
().
serializeNulls
();
}
}
public
class
DataObject
{
public
class
DataObject
{
public
static
final
String
STATIC_DATA
=
"bye"
;
public
static
final
String
STATIC_DATA
=
"bye"
;
...
@@ -252,6 +276,9 @@ public class GsonAutoConfigurationTests {
...
@@ -252,6 +276,9 @@ public class GsonAutoConfigurationTests {
@SuppressWarnings
(
"unused"
)
@SuppressWarnings
(
"unused"
)
private
Long
data
=
1L
;
private
Long
data
=
1L
;
@SuppressWarnings
(
"unused"
)
private
String
owner
=
null
;
public
void
setData
(
Long
data
)
{
public
void
setData
(
Long
data
)
{
this
.
data
=
data
;
this
.
data
=
data
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment