FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java/src/test/java/com/jsoniter/TestNested.java at master · lyBigdata/java · GitHub
lyBigdata
/
java
Public
forked from
json-iterator/java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
java
/
src
/
test
/
java
/
com
/
jsoniter
/
TestNested.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
62 lines (56 loc) · 2.49 KB
Breadcrumbs
java
/
src
/
test
/
java
/
com
/
jsoniter
/
TestNested.java
Copy path
File metadata and controls
62 lines (56 loc) · 2.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package
com
.
jsoniter
;
import
com
.
jsoniter
.
annotation
.
JsonIgnore
;
import
com
.
jsoniter
.
any
.
Any
;
import
junit
.
framework
.
TestCase
;
import
org
.
junit
.
Assert
;
import
java
.
io
.
IOException
;
public
class
TestNested
extends
TestCase
{
public
void
test_array_of_objects
()
throws
IOException
{
JsonIterator
iter
=
JsonIterator
.
parse
(
"[{'field1':'11','field2':'12'},{'field1':'21','field2':'22'}]"
.
replace
(
'\''
,
'"'
));
SimpleObject
[]
objects
=
iter
.
read
(
SimpleObject
[].
class
);
Assert
.
assertArrayEquals
(
new
SimpleObject
[]{
new
SimpleObject
() {{
field1
=
"11"
;
field2
=
"12"
;
}},
new
SimpleObject
() {{
field1
=
"21"
;
field2
=
"22"
;
}}
},
objects
);
iter
.
reset
(
iter
.
buf
);
Any
any
=
iter
.
readAny
();
assertEquals
(
"22"
,
any
.
toString
(
1
,
"field2"
));
}
public
void
test_get_all_array_elements_via_any
()
throws
IOException
{
Any
any
=
JsonIterator
.
deserialize
(
" [ {
\"
bar
\"
: 1 }, {
\"
bar
\"
: 3} ]"
);
Any
result
=
any
.
get
(
'*'
,
"bar"
);
assertEquals
(
"[ 1, 3]"
,
result
.
toString
());
any
=
Any
.
wrapAnyList
(
any
.
asList
());
// make it not lazy
result
=
any
.
get
(
'*'
,
"bar"
);
assertEquals
(
"[ 1, 3]"
,
result
.
toString
());
}
public
void
test_get_all_object_values_via_any
()
throws
IOException
{
Any
any
=
JsonIterator
.
deserialize
(
"{
\"
field1
\"
:[1,2],
\"
field2
\"
:[3,4]}"
);
Any
result
=
any
.
get
(
'*'
,
1
);
assertEquals
(
"{
\"
field1
\"
:2,
\"
field2
\"
:4}"
,
result
.
toString
());
any
=
Any
.
wrapAnyMap
(
any
.
asMap
());
// make it not lazy
result
=
any
.
get
(
'*'
,
1
);
assertEquals
(
"{
\"
field1
\"
:2,
\"
field2
\"
:4}"
,
result
.
toString
());
}
public
void
test_get_all_with_some_invalid_path
()
throws
IOException
{
Any
any
=
JsonIterator
.
deserialize
(
" [ {
\"
bar
\"
: 1 }, {
\"
foo
\"
: 3} ]"
);
Any
result
=
any
.
get
(
'*'
,
"bar"
);
assertEquals
(
"[ 1]"
,
result
.
toString
());
any
=
Any
.
wrapAnyList
(
any
.
asList
());
// make it not lazy
result
=
any
.
get
(
'*'
,
"bar"
);
assertEquals
(
"[ 1]"
,
result
.
toString
());
any
=
JsonIterator
.
deserialize
(
"{
\"
field1
\"
:[1,2],
\"
field2
\"
:[3]}"
);
result
=
any
.
get
(
'*'
,
1
);
assertEquals
(
"{
\"
field1
\"
:2}"
,
result
.
toString
());
any
=
Any
.
wrapAnyMap
(
any
.
asMap
());
// make it not lazy
result
=
any
.
get
(
'*'
,
1
);
assertEquals
(
"{
\"
field1
\"
:2}"
,
result
.
toString
());
}
}
Back
|
FazBrowse Home
|
New Git URL