FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java/src/test/java/com/jsoniter/TestCustomizeType.java at master · sandy-e/java · GitHub
sandy-e
/
java
Public
forked from
lnsandnkth/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
/
test
/
java
/
com
/
jsoniter
/
TestCustomizeType.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (52 loc) · 2.01 KB
Breadcrumbs
java
/
src
/
test
/
java
/
com
/
jsoniter
/
TestCustomizeType.java
Copy path
File metadata and controls
63 lines (52 loc) · 2.01 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
package
com
.
jsoniter
;
import
com
.
jsoniter
.
spi
.
Decoder
;
import
com
.
jsoniter
.
spi
.
EmptyExtension
;
import
com
.
jsoniter
.
spi
.
JsoniterSpi
;
import
junit
.
framework
.
TestCase
;
import
java
.
io
.
IOException
;
import
java
.
lang
.
reflect
.
Type
;
import
java
.
util
.
Date
;
public
class
TestCustomizeType
extends
TestCase
{
static
{
// JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_STRICTLY);
// JsonIterator.setMode(DecodingMode.REFLECTION_MODE);
}
public
static
class
MyDate2
{
Date
date
;
}
public
static
class
FieldWithMyDate2
{
public
MyDate2
field
;
}
public
void
test_customize_through_extension
()
throws
IOException
{
JsoniterSpi
.
registerExtension
(
new
EmptyExtension
() {
@
Override
public
Decoder
createDecoder
(
String
cacheKey
,
Type
type
) {
if
(
type
==
MyDate2
.
class
) {
return
new
Decoder
() {
@
Override
public
Object
decode
(
final
JsonIterator
iter1
)
throws
IOException
{
return
new
MyDate2
() {{
date
=
new
Date
(
iter1
.
readLong
());
}};
}
};
}
return
null
;
}
});
JsonIterator
iter
=
JsonIterator
.
parse
(
"{'field': 1481365190000}"
.
replace
(
'\''
,
'"'
));
FieldWithMyDate2
obj
=
iter
.
read
(
FieldWithMyDate2
.
class
);
assertEquals
(
1481365190000L
,
obj
.
field
.
date
.
getTime
());
}
public
static
interface
MyInterface
{
}
public
static
class
MyObject
implements
MyInterface
{
public
long
field1
;
}
public
void
test_customize_impl
()
throws
IOException
{
JsoniterSpi
.
registerTypeImplementation
(
MyInterface
.
class
,
MyObject
.
class
);
JsonIterator
iter
=
JsonIterator
.
parse
(
"{'field1': 1481365190000}"
.
replace
(
'\''
,
'"'
));
MyObject
obj
= (
MyObject
)
iter
.
read
(
MyInterface
.
class
);
assertEquals
(
1481365190000L
,
obj
.
field1
);
}
}
Back
|
FazBrowse Home
|
New Git URL