FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java/src/main/java/com/jsoniter/ReflectionMapDecoder.java at master · structure/java · GitHub
structure
/
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
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java
/
src
/
main
/
java
/
com
/
jsoniter
/
ReflectionMapDecoder.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (56 loc) · 1.91 KB
Breadcrumbs
java
/
src
/
main
/
java
/
com
/
jsoniter
/
ReflectionMapDecoder.java
Copy path
File metadata and controls
64 lines (56 loc) · 1.91 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
package
com
.
jsoniter
;
import
com
.
jsoniter
.
spi
.*;
import
java
.
io
.
IOException
;
import
java
.
lang
.
reflect
.
Constructor
;
import
java
.
lang
.
reflect
.
Type
;
import
java
.
util
.
Map
;
class
ReflectionMapDecoder
implements
Decoder
{
private
final
Constructor
ctor
;
private
final
Decoder
valueTypeDecoder
;
private
final
Decoder
mapKeyDecoder
;
public
ReflectionMapDecoder
(
Class
clazz
,
Type
[]
typeArgs
) {
try
{
ctor
=
clazz
.
getConstructor
();
}
catch
(
NoSuchMethodException
e
) {
throw
new
JsonException
(
e
);
}
Type
keyType
=
typeArgs
[
0
];
mapKeyDecoder
=
MapKeyDecoders
.
registerOrGetExisting
(
keyType
);
TypeLiteral
valueTypeLiteral
=
TypeLiteral
.
create
(
typeArgs
[
1
]);
valueTypeDecoder
=
Codegen
.
getDecoder
(
valueTypeLiteral
.
getDecoderCacheKey
(),
typeArgs
[
1
]);
}
@
Override
public
Object
decode
(
JsonIterator
iter
)
throws
IOException
{
try
{
return
decode_
(
iter
);
}
catch
(
JsonException
e
) {
throw
e
;
}
catch
(
Exception
e
) {
throw
new
JsonException
(
e
);
}
}
private
Object
decode_
(
JsonIterator
iter
)
throws
Exception
{
Map
map
= (
Map
)
CodegenAccess
.
resetExistingObject
(
iter
);
if
(
iter
.
readNull
()) {
return
null
;
}
if
(
map
==
null
) {
map
= (
Map
)
ctor
.
newInstance
();
}
if
(!
CodegenAccess
.
readObjectStart
(
iter
)) {
return
map
;
}
do
{
Object
decodedMapKey
=
readMapKey
(
iter
);
map
.
put
(
decodedMapKey
,
valueTypeDecoder
.
decode
(
iter
));
}
while
(
CodegenAccess
.
nextToken
(
iter
) ==
','
);
return
map
;
}
private
Object
readMapKey
(
JsonIterator
iter
)
throws
IOException
{
Object
key
=
mapKeyDecoder
.
decode
(
iter
);
if
(
':'
!=
IterImpl
.
nextToken
(
iter
)) {
throw
iter
.
reportError
(
"readMapKey"
,
"expect :"
);
}
return
key
;
}
}
Back
|
FazBrowse Home
|
New Git URL