Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
熊鹏飞
/
xxljob220
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a6cff8f6
authored
Oct 26, 2019
by
ylqin
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
use junit test to replace main() for testing
parent
111fdc4f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
28 deletions
xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/JacksonUtil.java
xxl-job-admin/src/test/java/com/xxl/job/admin/core/util/JacksonUtilTest.java
xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/JacksonUtil.java
View file @
a6cff8f6
...
@@ -9,8 +9,6 @@ import org.slf4j.Logger;
...
@@ -9,8 +9,6 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
/**
* Jackson util
* Jackson util
...
@@ -91,30 +89,4 @@ public class JacksonUtil {
...
@@ -91,30 +89,4 @@ public class JacksonUtil {
}
}
return
null
;
return
null
;
}
}
/*public static <T> T readValueRefer(String jsonStr, Class<T> clazz) {
try {
return getInstance().readValue(jsonStr, new TypeReference<T>() { });
} catch (JsonParseException e) {
logger.error(e.getMessage(), e);
} catch (JsonMappingException e) {
logger.error(e.getMessage(), e);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
return null;
}*/
public
static
void
main
(
String
[]
args
)
{
try
{
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"aaa"
,
"111"
);
map
.
put
(
"bbb"
,
"222"
);
String
json
=
writeValueAsString
(
map
);
System
.
out
.
println
(
json
);
System
.
out
.
println
(
readValue
(
json
,
Map
.
class
));
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
}
}
}
xxl-job-admin/src/test/java/com/xxl/job/admin/core/util/JacksonUtilTest.java
0 → 100644
View file @
a6cff8f6
package
com
.
xxl
.
job
.
admin
.
core
.
util
;
import
org.hamcrest.core.Is
;
import
org.junit.Test
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
com
.
xxl
.
job
.
admin
.
core
.
util
.
JacksonUtil
.
writeValueAsString
;
import
static
org
.
hamcrest
.
core
.
Is
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
JacksonUtilTest
{
@Test
public
void
shouldWriteValueAsString
()
{
//given
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"aaa"
,
"111"
);
map
.
put
(
"bbb"
,
"222"
);
//when
String
json
=
writeValueAsString
(
map
);
//then
assertThat
(
json
,
is
(
"{\"aaa\":\"111\",\"bbb\":\"222\"}"
));
}
@Test
public
void
shouldReadValueAsObject
()
{
//given
String
jsonString
=
"{\"aaa\":\"111\",\"bbb\":\"222\"}"
;
//when
Map
result
=
JacksonUtil
.
readValue
(
jsonString
,
Map
.
class
);
//then
assertThat
(
result
.
get
(
"aaa"
),
Is
.<
Object
>
is
(
"111"
));
assertThat
(
result
.
get
(
"bbb"
),
Is
.<
Object
>
is
(
"222"
));
}
}
\ No newline at end of file
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