FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java/src/main/java/com/jsoniter/ReflectionArrayDecoder.java at master · Howeu/java · GitHub
Howeu
/
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
/
main
/
java
/
com
/
jsoniter
/
ReflectionArrayDecoder.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (68 loc) · 2.46 KB
Breadcrumbs
java
/
src
/
main
/
java
/
com
/
jsoniter
/
ReflectionArrayDecoder.java
Copy path
File metadata and controls
74 lines (68 loc) · 2.46 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
63
64
65
66
67
68
69
70
71
72
73
74
package
com
.
jsoniter
;
import
com
.
jsoniter
.
spi
.
Decoder
;
import
com
.
jsoniter
.
spi
.
JsoniterSpi
;
import
com
.
jsoniter
.
spi
.
TypeLiteral
;
import
java
.
io
.
IOException
;
import
java
.
lang
.
reflect
.
Array
;
class
ReflectionArrayDecoder
implements
Decoder
{
private
final
Class
componentType
;
private
final
Decoder
compTypeDecoder
;
public
ReflectionArrayDecoder
(
Class
clazz
) {
componentType
=
clazz
.
getComponentType
();
compTypeDecoder
=
Codegen
.
getDecoder
(
TypeLiteral
.
create
(
componentType
).
getDecoderCacheKey
(),
componentType
);
}
@
Override
public
Object
decode
(
JsonIterator
iter
)
throws
IOException
{
CodegenAccess
.
resetExistingObject
(
iter
);
if
(
iter
.
readNull
()) {
return
null
;
}
if
(!
CodegenAccess
.
readArrayStart
(
iter
)) {
return
Array
.
newInstance
(
componentType
,
0
);
}
Object
a1
=
compTypeDecoder
.
decode
(
iter
);
if
(
CodegenAccess
.
nextToken
(
iter
) !=
','
) {
Object
arr
=
Array
.
newInstance
(
componentType
,
1
);
Array
.
set
(
arr
,
0
,
a1
);
return
arr
;
}
Object
a2
=
compTypeDecoder
.
decode
(
iter
);
if
(
CodegenAccess
.
nextToken
(
iter
) !=
','
) {
Object
arr
=
Array
.
newInstance
(
componentType
,
2
);
Array
.
set
(
arr
,
0
,
a1
);
Array
.
set
(
arr
,
1
,
a2
);
return
arr
;
}
Object
a3
=
compTypeDecoder
.
decode
(
iter
);
if
(
CodegenAccess
.
nextToken
(
iter
) !=
','
) {
Object
arr
=
Array
.
newInstance
(
componentType
,
3
);
Array
.
set
(
arr
,
0
,
a1
);
Array
.
set
(
arr
,
1
,
a2
);
Array
.
set
(
arr
,
2
,
a3
);
return
arr
;
}
Object
a4
=
compTypeDecoder
.
decode
(
iter
);
Object
arr
=
Array
.
newInstance
(
componentType
,
8
);
Array
.
set
(
arr
,
0
,
a1
);
Array
.
set
(
arr
,
1
,
a2
);
Array
.
set
(
arr
,
2
,
a3
);
Array
.
set
(
arr
,
3
,
a4
);
int
i
=
4
;
int
arrLen
=
8
;
while
(
CodegenAccess
.
nextToken
(
iter
) ==
','
) {
if
(
i
==
arrLen
) {
Object
newArr
=
Array
.
newInstance
(
componentType
,
2
*
arrLen
);
System
.
arraycopy
(
arr
,
0
,
newArr
,
0
,
arrLen
);
arr
=
newArr
;
arrLen
=
2
*
arrLen
;
}
Array
.
set
(
arr
,
i
++,
compTypeDecoder
.
decode
(
iter
));
}
if
(
i
==
arrLen
) {
return
arr
;
}
Object
newArr
=
Array
.
newInstance
(
componentType
,
i
);
System
.
arraycopy
(
arr
,
0
,
newArr
,
0
,
i
);
return
newArr
;
}
}
Back
|
FazBrowse Home
|
New Git URL