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
84d3b6a4
Commit
84d3b6a4
authored
May 15, 2016
by
Casey Scarborough
Committed by
Stephane Nicoll
May 16, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unchecked casts
Closes gh-5975
parent
4023637b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
8 deletions
+10
-8
GsonJsonParser.java
...in/java/org/springframework/boot/json/GsonJsonParser.java
+5
-4
JacksonJsonParser.java
...java/org/springframework/boot/json/JacksonJsonParser.java
+5
-4
No files found.
spring-boot/src/main/java/org/springframework/boot/json/GsonJsonParser.java
View file @
84d3b6a4
...
@@ -21,6 +21,7 @@ import java.util.Map;
...
@@ -21,6 +21,7 @@ import java.util.Map;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.reflect.TypeToken
;
/**
/**
* Thin wrapper to adapt {@link Gson} to a {@link JsonParser}.
* Thin wrapper to adapt {@link Gson} to a {@link JsonParser}.
...
@@ -35,24 +36,24 @@ public class GsonJsonParser implements JsonParser {
...
@@ -35,24 +36,24 @@ public class GsonJsonParser implements JsonParser {
private
Gson
gson
=
new
GsonBuilder
().
create
();
private
Gson
gson
=
new
GsonBuilder
().
create
();
@Override
@Override
@SuppressWarnings
(
"unchecked"
)
public
Map
<
String
,
Object
>
parseMap
(
String
json
)
{
public
Map
<
String
,
Object
>
parseMap
(
String
json
)
{
if
(
json
!=
null
)
{
if
(
json
!=
null
)
{
json
=
json
.
trim
();
json
=
json
.
trim
();
if
(
json
.
startsWith
(
"{"
))
{
if
(
json
.
startsWith
(
"{"
))
{
return
this
.
gson
.
fromJson
(
json
,
Map
.
class
);
TypeToken
<
Map
<
String
,
Object
>>
type
=
new
TypeToken
<
Map
<
String
,
Object
>>()
{
};
return
this
.
gson
.
fromJson
(
json
,
type
.
getType
());
}
}
}
}
throw
new
IllegalArgumentException
(
"Cannot parse JSON"
);
throw
new
IllegalArgumentException
(
"Cannot parse JSON"
);
}
}
@Override
@Override
@SuppressWarnings
(
"unchecked"
)
public
List
<
Object
>
parseList
(
String
json
)
{
public
List
<
Object
>
parseList
(
String
json
)
{
if
(
json
!=
null
)
{
if
(
json
!=
null
)
{
json
=
json
.
trim
();
json
=
json
.
trim
();
if
(
json
.
startsWith
(
"["
))
{
if
(
json
.
startsWith
(
"["
))
{
return
this
.
gson
.
fromJson
(
json
,
List
.
class
);
TypeToken
<
List
<
Object
>>
type
=
new
TypeToken
<
List
<
Object
>>()
{
};
return
this
.
gson
.
fromJson
(
json
,
type
.
getType
());
}
}
}
}
throw
new
IllegalArgumentException
(
"Cannot parse JSON"
);
throw
new
IllegalArgumentException
(
"Cannot parse JSON"
);
...
...
spring-boot/src/main/java/org/springframework/boot/json/JacksonJsonParser.java
View file @
84d3b6a4
...
@@ -19,6 +19,7 @@ package org.springframework.boot.json;
...
@@ -19,6 +19,7 @@ package org.springframework.boot.json;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
/**
/**
...
@@ -30,10 +31,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
...
@@ -30,10 +31,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public
class
JacksonJsonParser
implements
JsonParser
{
public
class
JacksonJsonParser
implements
JsonParser
{
@Override
@Override
@SuppressWarnings
(
"unchecked"
)
public
Map
<
String
,
Object
>
parseMap
(
String
json
)
{
public
Map
<
String
,
Object
>
parseMap
(
String
json
)
{
try
{
try
{
return
new
ObjectMapper
().
readValue
(
json
,
Map
.
class
);
TypeReference
<
Map
<
String
,
Object
>>
type
=
new
TypeReference
<
Map
<
String
,
Object
>>()
{
};
return
new
ObjectMapper
().
readValue
(
json
,
type
);
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
throw
new
IllegalArgumentException
(
"Cannot parse JSON"
,
ex
);
throw
new
IllegalArgumentException
(
"Cannot parse JSON"
,
ex
);
...
@@ -41,10 +42,10 @@ public class JacksonJsonParser implements JsonParser {
...
@@ -41,10 +42,10 @@ public class JacksonJsonParser implements JsonParser {
}
}
@Override
@Override
@SuppressWarnings
(
"unchecked"
)
public
List
<
Object
>
parseList
(
String
json
)
{
public
List
<
Object
>
parseList
(
String
json
)
{
try
{
try
{
return
new
ObjectMapper
().
readValue
(
json
,
List
.
class
);
TypeReference
<
List
<
Object
>>
type
=
new
TypeReference
<
List
<
Object
>>()
{
};
return
new
ObjectMapper
().
readValue
(
json
,
type
);
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
throw
new
IllegalArgumentException
(
"Cannot parse JSON"
,
ex
);
throw
new
IllegalArgumentException
(
"Cannot parse JSON"
,
ex
);
...
...
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