FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java/src/test/java/com/jsoniter/TestSpiPropertyDecoder.java at master · junplus/java · GitHub
junplus
/
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
/
TestSpiPropertyDecoder.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (38 loc) · 1.41 KB
Breadcrumbs
java
/
src
/
test
/
java
/
com
/
jsoniter
/
TestSpiPropertyDecoder.java
Copy path
File metadata and controls
45 lines (38 loc) · 1.41 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
package
com
.
jsoniter
;
import
com
.
jsoniter
.
spi
.
Decoder
;
import
com
.
jsoniter
.
spi
.
JsoniterSpi
;
import
com
.
jsoniter
.
spi
.
TypeLiteral
;
import
junit
.
framework
.
TestCase
;
import
java
.
io
.
IOException
;
public
class
TestSpiPropertyDecoder
extends
TestCase
{
static
{
// JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH);
}
public
static
class
TestObject1
<
A
> {
public
String
field
;
}
public
void
test_PropertyDecoder
() {
JsoniterSpi
.
registerPropertyDecoder
(
TestObject1
.
class
,
"field"
,
new
Decoder
() {
@
Override
public
Object
decode
(
JsonIterator
iter
)
throws
IOException
{
iter
.
skip
();
return
"hello"
;
}
});
TestObject1
obj
=
JsonIterator
.
deserialize
(
"{
\"
field
\"
:100}"
,
TestObject1
.
class
);
assertEquals
(
"hello"
,
obj
.
field
);
}
public
void
test_PropertyDecoder_for_type_literal
() {
TypeLiteral
<
TestObject1
<
Object
>>
typeLiteral
=
new
TypeLiteral
<
TestObject1
<
Object
>>() {
};
JsoniterSpi
.
registerPropertyDecoder
(
typeLiteral
,
"field"
,
new
Decoder
() {
@
Override
public
Object
decode
(
JsonIterator
iter
)
throws
IOException
{
iter
.
skip
();
return
"world"
;
}
});
TestObject1
obj
=
JsonIterator
.
deserialize
(
"{
\"
field
\"
:100}"
,
typeLiteral
);
assertEquals
(
"world"
,
obj
.
field
);
}
}
Back
|
FazBrowse Home
|
New Git URL