Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
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
YZG
yzg-util
Commits
05d40d89
Commit
05d40d89
authored
Aug 18, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
升级新版本
parent
02ea3059
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
0 deletions
+118
-0
TestJsonHelper.java
yzg-util-base/src/test/java/helper/TestJsonHelper.java
+118
-0
No files found.
yzg-util-base/src/test/java/helper/TestJsonHelper.java
0 → 100644
View file @
05d40d89
package
helper
;
import
com.alibaba.fastjson.TypeReference
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
TestJsonHelper
{
@Test
public
void
test
()
{
Fanxing
<
FanxingData
>
from
=
new
Fanxing
<>(
new
FanxingData
(
"颜佐光"
));
from
.
setList
(
null
);
from
.
setListNull
(
null
);
String
json
=
JsonHelper
.
serialize
(
from
);
Fanxing
<
FanxingData
>
to
=
JsonHelper
.
deserialize
(
json
,
new
TypeReference
<
Fanxing
<
FanxingData
>>()
{
});
Assert
.
assertNotEquals
(
from
,
to
);
Assert
.
assertNotEquals
(
from
.
getData
(),
to
.
getData
());
Assert
.
assertEquals
(
from
.
getData
().
getName
(),
to
.
getData
().
getName
());
Assert
.
assertFalse
(
to
.
getList
()
==
null
);
Assert
.
assertTrue
(
to
.
getListNull
()
==
null
);
}
@Test
public
void
test1
()
{
Fanxing
<
Fanxing
<
FanxingData
>>
from
=
new
Fanxing
<>(
new
Fanxing
<>(
new
FanxingData
(
"颜佐光"
)));
from
.
setList
(
null
);
from
.
setListNull
(
null
);
String
json
=
JsonHelper
.
serialize
(
from
);
Fanxing
<
Fanxing
<
FanxingData
>>
to
=
JsonHelper
.
deserialize
(
json
,
new
TypeReference
<
Fanxing
<
Fanxing
<
FanxingData
>>>()
{
});
Assert
.
assertNotEquals
(
from
,
to
);
Assert
.
assertNotEquals
(
from
.
getData
(),
to
.
getData
());
Assert
.
assertEquals
(
from
.
getData
().
getData
().
getName
(),
to
.
getData
().
getData
().
getName
());
Assert
.
assertFalse
(
to
.
getList
()
==
null
);
Assert
.
assertTrue
(
to
.
getListNull
()
==
null
);
}
}
class
Fanxing
<
T
>
{
private
T
data
;
/**
* null值反序列化后不会为null
*/
private
List
<
T
>
list
=
new
ArrayList
<>();
/**
* null值反序列化后后会为null
*/
private
List
<
T
>
listNull
;
/**
* 当没有无参构造函数时无法序列化
*/
public
Fanxing
()
{
}
public
Fanxing
(
T
data
)
{
this
.
data
=
data
;
}
public
T
getData
()
{
return
data
;
}
public
void
setData
(
T
data
)
{
this
.
data
=
data
;
}
public
List
<
T
>
getList
()
{
return
list
;
}
public
void
setList
(
List
<
T
>
list
)
{
this
.
list
=
list
;
}
public
List
<
T
>
getListNull
()
{
return
listNull
;
}
public
void
setListNull
(
List
<
T
>
listNull
)
{
this
.
listNull
=
listNull
;
}
}
class
FanxingData
{
private
String
name
;
/**
* 当没有无参构造函数时无法序列化
*/
public
FanxingData
()
{
}
public
FanxingData
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
\ 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