FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java/src/main/java/com/jsoniter/MapKeyDecoders.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
/
MapKeyDecoders.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
77 lines (62 loc) · 2.31 KB
Breadcrumbs
java
/
src
/
main
/
java
/
com
/
jsoniter
/
MapKeyDecoders.java
Copy path
File metadata and controls
77 lines (62 loc) · 2.31 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
75
76
77
package
com
.
jsoniter
;
import
com
.
jsoniter
.
spi
.*;
import
java
.
io
.
IOException
;
import
java
.
lang
.
reflect
.
Type
;
class
MapKeyDecoders
{
public
static
Decoder
registerOrGetExisting
(
Type
mapKeyType
) {
String
cacheKey
=
JsoniterSpi
.
getMapKeyDecoderCacheKey
(
mapKeyType
);
Decoder
mapKeyDecoder
=
JsoniterSpi
.
getMapKeyDecoder
(
cacheKey
);
if
(
null
!=
mapKeyDecoder
) {
return
mapKeyDecoder
;
}
mapKeyDecoder
=
createMapKeyDecoder
(
mapKeyType
);
JsoniterSpi
.
addNewMapDecoder
(
cacheKey
,
mapKeyDecoder
);
return
mapKeyDecoder
;
}
private
static
Decoder
createMapKeyDecoder
(
Type
mapKeyType
) {
if
(
String
.
class
==
mapKeyType
) {
return
new
StringKeyDecoder
();
}
if
(
mapKeyType
instanceof
Class
&& ((
Class
)
mapKeyType
).
isEnum
()) {
return
new
EnumKeyDecoder
((
Class
)
mapKeyType
);
}
Decoder
decoder
=
CodegenImplNative
.
NATIVE_DECODERS
.
get
(
mapKeyType
);
if
(
decoder
!=
null
) {
return
new
NumberKeyDecoder
(
decoder
);
}
throw
new
JsonException
(
"can not decode map key type: "
+
mapKeyType
);
}
private
static
class
StringKeyDecoder
implements
Decoder
{
@
Override
public
Object
decode
(
JsonIterator
iter
)
throws
IOException
{
return
iter
.
readString
();
}
}
private
static
class
EnumKeyDecoder
implements
Decoder
{
private
final
Class
enumClass
;
private
EnumKeyDecoder
(
Class
enumClass
) {
this
.
enumClass
=
enumClass
;
}
@
Override
public
Object
decode
(
JsonIterator
iter
)
throws
IOException
{
return
iter
.
read
(
enumClass
);
}
}
private
static
class
NumberKeyDecoder
implements
Decoder
{
private
final
Decoder
decoder
;
private
NumberKeyDecoder
(
Decoder
decoder
) {
this
.
decoder
=
decoder
;
}
@
Override
public
Object
decode
(
JsonIterator
iter
)
throws
IOException
{
if
(
IterImpl
.
nextToken
(
iter
) !=
'"'
) {
throw
iter
.
reportError
(
"decode number map key"
,
"expect
\"
"
);
}
Object
key
=
decoder
.
decode
(
iter
);
if
(
IterImpl
.
nextToken
(
iter
) !=
'"'
) {
throw
iter
.
reportError
(
"decode number map key"
,
"expect
\"
"
);
}
return
key
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL