FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java/src/test/java/com/jsoniter/TestJackson.java at master · iCodeIN/java · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
iCodeIN
/
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
/
test
/
java
/
com
/
jsoniter
/
TestJackson.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
73 lines (60 loc) · 2.39 KB
Breadcrumbs
java
/
src
/
test
/
java
/
com
/
jsoniter
/
TestJackson.java
Copy path
File metadata and controls
73 lines (60 loc) · 2.39 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
package
com
.
jsoniter
;
import
com
.
fasterxml
.
jackson
.
annotation
.
JsonAnySetter
;
import
com
.
fasterxml
.
jackson
.
annotation
.
JsonIgnore
;
import
com
.
fasterxml
.
jackson
.
annotation
.
JsonProperty
;
import
com
.
fasterxml
.
jackson
.
databind
.
ObjectMapper
;
import
com
.
jsoniter
.
extra
.
JacksonCompatibilityMode
;
import
junit
.
framework
.
TestCase
;
import
java
.
io
.
IOException
;
public
class
TestJackson
extends
TestCase
{
static
{
// JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH);
}
private
ObjectMapper
objectMapper
;
public
void
setUp
() {
objectMapper
=
new
ObjectMapper
();
}
public
static
class
TestObject1
{
private
int
_id
;
private
String
_name
;
@
JsonAnySetter
public
void
setProperties
(
String
key
,
Object
value
) {
if
(
key
.
equals
(
"name"
)) {
_name
= (
String
)
value
;
}
else
if
(
key
.
equals
(
"id"
)) {
_id
= ((
Number
)
value
).
intValue
();
}
}
}
public
void
test_JsonAnySetter
()
throws
IOException
{
TestObject1
obj
=
objectMapper
.
readValue
(
"{
\"
name
\"
:
\"
hello
\"
,
\"
id
\"
:100}"
,
TestObject1
.
class
);
assertEquals
(
"hello"
,
obj
.
_name
);
assertEquals
(
100
,
obj
.
_id
);
obj
=
JsonIterator
.
deserialize
(
new
JacksonCompatibilityMode
.
Builder
().
build
(),
"{
\"
name
\"
:
\"
hello
\"
,
\"
id
\"
:100}"
,
TestObject1
.
class
);
assertEquals
(
"hello"
,
obj
.
_name
);
assertEquals
(
100
,
obj
.
_id
);
}
public
static
class
TestObject2
{
@
JsonProperty
(
"field-1"
)
public
String
field1
;
}
public
void
test_JsonProperty
()
throws
IOException
{
TestObject2
obj
=
objectMapper
.
readValue
(
"{
\"
field-1
\"
:
\"
hello
\"
}"
,
TestObject2
.
class
);
assertEquals
(
"hello"
,
obj
.
field1
);
obj
=
JsonIterator
.
deserialize
(
new
JacksonCompatibilityMode
.
Builder
().
build
(),
"{
\"
field-1
\"
:
\"
hello
\"
}"
,
TestObject2
.
class
);
assertEquals
(
"hello"
,
obj
.
field1
);
}
public
static
class
TestObject3
{
@
JsonIgnore
public
String
field1
;
}
public
void
test_JsonIgnore
()
throws
IOException
{
TestObject3
obj
=
objectMapper
.
readValue
(
"{
\"
field1
\"
:
\"
hello
\"
}"
,
TestObject3
.
class
);
assertNull
(
obj
.
field1
);
obj
=
JsonIterator
.
deserialize
(
new
JacksonCompatibilityMode
.
Builder
().
build
(),
"{
\"
field1
\"
:
\"
hello
\"
}"
,
TestObject3
.
class
);
assertNull
(
obj
.
field1
);
}
}
Back
|
FazBrowse Home
|
New Git URL