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
08ddbe79
Commit
08ddbe79
authored
Nov 20, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add GsonJsonParser
parent
ab6878ab
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
0 deletions
+85
-0
pom.xml
spring-boot/pom.xml
+5
-0
GsonJsonParser.java
...in/java/org/springframework/boot/json/GsonJsonParser.java
+46
-0
JsonParser.java
...c/main/java/org/springframework/boot/json/JsonParser.java
+1
-0
JsonParserFactory.java
...java/org/springframework/boot/json/JsonParserFactory.java
+3
-0
GsonJsonParserTests.java
...va/org/springframework/boot/json/GsonJsonParserTests.java
+30
-0
No files found.
spring-boot/pom.xml
View file @
08ddbe79
...
...
@@ -54,6 +54,11 @@
<artifactId>
jackson-databind
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
javax.jms
</groupId>
<artifactId>
jms-api
</artifactId>
...
...
spring-boot/src/main/java/org/springframework/boot/json/GsonJsonParser.java
0 → 100644
View file @
08ddbe79
/*
* Copyright 2012-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
json
;
import
java.util.List
;
import
java.util.Map
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
/**
* @author dsyer
*/
public
class
GsonJsonParser
implements
JsonParser
{
private
Gson
gson
=
new
GsonBuilder
().
create
();
@Override
public
Map
<
String
,
Object
>
parseMap
(
String
json
)
{
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Object
>
value
=
this
.
gson
.
fromJson
(
json
,
Map
.
class
);
return
value
;
}
@Override
public
List
<
Object
>
parseList
(
String
json
)
{
@SuppressWarnings
(
"unchecked"
)
List
<
Object
>
value
=
this
.
gson
.
fromJson
(
json
,
List
.
class
);
return
value
;
}
}
spring-boot/src/main/java/org/springframework/boot/json/JsonParser.java
View file @
08ddbe79
...
...
@@ -26,6 +26,7 @@ import java.util.Map;
* @see JsonParserFactory
* @see SimpleJsonParser
* @see JacksonJsonParser
* @see GsonJsonParser
* @see YamlJsonParser
*/
public
interface
JsonParser
{
...
...
spring-boot/src/main/java/org/springframework/boot/json/JsonParserFactory.java
View file @
08ddbe79
...
...
@@ -37,6 +37,9 @@ public abstract class JsonParserFactory {
if
(
ClassUtils
.
isPresent
(
"com.fasterxml.jackson.databind.ObjectMapper"
,
null
))
{
return
new
JacksonJsonParser
();
}
if
(
ClassUtils
.
isPresent
(
"com.google.gson.Gson"
,
null
))
{
return
new
GsonJsonParser
();
}
if
(
ClassUtils
.
isPresent
(
"org.yaml.snakeyaml.Yaml"
,
null
))
{
return
new
YamlJsonParser
();
}
...
...
spring-boot/src/test/java/org/springframework/boot/json/GsonJsonParserTests.java
0 → 100644
View file @
08ddbe79
/*
* Copyright 2012-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
json
;
/**
* Tests for {@link YamlJsonParser}.
*
* @author Dave Syer
*/
public
class
GsonJsonParserTests
extends
SimpleJsonParserTests
{
@Override
protected
JsonParser
getParser
()
{
return
new
GsonJsonParser
();
}
}
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