Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94fd304

Browse files
YakoYako
authored andcommitted
"name":"jobs"
1 parent 99ba251 commit 94fd304

File tree

9 files changed

+278
-6
lines changed

9 files changed

+278
-6
lines changed

src/main/java/com/alibaba/fastjson/parser/deserializer/FieldDeserializer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public void setValue(Object object, Object value) {
7878
}
7979
}
8080
} else {
81+
if (value == null && fieldInfo.getFieldClass().isPrimitive()) {
82+
return;
83+
}
8184
method.invoke(object, value);
8285
}
8386
} catch (Exception e) {

src/main/java/com/alibaba/fastjson/util/TypeUtils.java

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ public static final Byte castToByte(Object value) {
8989
if (strVal.length() == 0) {
9090
return null;
9191
}
92+
93+
if ("null".equals(strVal)) {
94+
return null;
95+
}
96+
9297
return Byte.parseByte(strVal);
9398
}
9499

@@ -135,6 +140,11 @@ public static final Short castToShort(Object value) {
135140
if (strVal.length() == 0) {
136141
return null;
137142
}
143+
144+
if ("null".equals(strVal)) {
145+
return null;
146+
}
147+
138148
return Short.parseShort(strVal);
139149
}
140150

@@ -197,6 +207,10 @@ public static final Float castToFloat(Object value) {
197207
if (strVal.length() == 0) {
198208
return null;
199209
}
210+
211+
if ("null".equals(strVal)) {
212+
return null;
213+
}
200214

201215
return Float.parseFloat(strVal);
202216
}
@@ -218,6 +232,11 @@ public static final Double castToDouble(Object value) {
218232
if (strVal.length() == 0) {
219233
return null;
220234
}
235+
236+
if ("null".equals(strVal)) {
237+
return null;
238+
}
239+
221240
return Double.parseDouble(strVal);
222241
}
223242

@@ -372,6 +391,10 @@ public static final Long castToLong(Object value) {
372391
if (strVal.length() == 0) {
373392
return null;
374393
}
394+
395+
if ("null".equals(strVal)) {
396+
return null;
397+
}
375398

376399
try {
377400
return Long.parseLong(strVal);
@@ -412,6 +435,10 @@ public static final Integer castToInt(Object value) {
412435
if (strVal.length() == 0) {
413436
return null;
414437
}
438+
439+
if ("null".equals(strVal)) {
440+
return null;
441+
}
415442

416443
return Integer.parseInt(strVal);
417444
}
@@ -444,25 +471,29 @@ public static final Boolean castToBoolean(Object value) {
444471
}
445472

446473
if (value instanceof String) {
447-
String str = (String) value;
448-
if (str.length() == 0) {
474+
String strVal = (String) value;
475+
if (strVal.length() == 0) {
449476
return null;
450477
}
451478

452-
if ("true".equals(str)) {
479+
if ("true".equalsIgnoreCase(strVal)) {
453480
return Boolean.TRUE;
454481
}
455-
if ("false".equals(str)) {
482+
if ("false".equalsIgnoreCase(strVal)) {
456483
return Boolean.FALSE;
457484
}
458485

459-
if ("1".equals(str)) {
486+
if ("1".equals(strVal)) {
460487
return Boolean.TRUE;
461488
}
462489

463-
if ("0".equals(str)) {
490+
if ("0".equals(strVal)) {
464491
return Boolean.FALSE;
465492
}
493+
494+
if ("null".equals(strVal)) {
495+
return null;
496+
}
466497
}
467498

468499
throw new JSONException("can not cast to int, value : " + value);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.alibaba.json.bvt.bug;
2+
3+
import junit.framework.TestCase;
4+
5+
import com.alibaba.fastjson.JSON;
6+
7+
public class Bug_for_primitive_boolean extends TestCase {
8+
9+
public void test_emptyStr() throws Exception {
10+
JSON.parseObject("{\"value\":\"\"}", VO.class);
11+
}
12+
13+
public void test_null() throws Exception {
14+
JSON.parseObject("{\"value\":null}", VO.class);
15+
}
16+
17+
public void test_strNull() throws Exception {
18+
JSON.parseObject("{\"value\":\"null\"}", VO.class);
19+
}
20+
21+
public static class VO {
22+
23+
private boolean value;
24+
25+
public boolean getValue() {
26+
return value;
27+
}
28+
29+
public void setValue(boolean value) {
30+
throw new UnsupportedOperationException();
31+
}
32+
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.alibaba.json.bvt.bug;
2+
3+
import junit.framework.TestCase;
4+
5+
import com.alibaba.fastjson.JSON;
6+
7+
public class Bug_for_primitive_byte extends TestCase {
8+
9+
public void test_emptyStr() throws Exception {
10+
JSON.parseObject("{\"value\":\"\"}", VO.class);
11+
}
12+
13+
public void test_null() throws Exception {
14+
JSON.parseObject("{\"value\":null}", VO.class);
15+
}
16+
17+
public void test_strNull() throws Exception {
18+
JSON.parseObject("{\"value\":\"null\"}", VO.class);
19+
}
20+
21+
public static class VO {
22+
23+
private byte value;
24+
25+
public byte getValue() {
26+
return value;
27+
}
28+
29+
public void setValue(byte value) {
30+
throw new UnsupportedOperationException();
31+
}
32+
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.alibaba.json.bvt.bug;
2+
3+
import junit.framework.TestCase;
4+
5+
import com.alibaba.fastjson.JSON;
6+
7+
public class Bug_for_primitive_double extends TestCase {
8+
9+
public void test_emptyStr() throws Exception {
10+
JSON.parseObject("{\"value\":\"\"}", VO.class);
11+
}
12+
13+
public void test_null() throws Exception {
14+
JSON.parseObject("{\"value\":null}", VO.class);
15+
}
16+
17+
public void test_strNull() throws Exception {
18+
JSON.parseObject("{\"value\":\"null\"}", VO.class);
19+
}
20+
21+
public static class VO {
22+
23+
private double value;
24+
25+
public double getValue() {
26+
return value;
27+
}
28+
29+
public void setValue(double value) {
30+
throw new UnsupportedOperationException();
31+
}
32+
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.alibaba.json.bvt.bug;
2+
3+
import junit.framework.TestCase;
4+
5+
import com.alibaba.fastjson.JSON;
6+
7+
public class Bug_for_primitive_float extends TestCase {
8+
9+
public void test_emptyStr() throws Exception {
10+
JSON.parseObject("{\"value\":\"\"}", VO.class);
11+
}
12+
13+
public void test_null() throws Exception {
14+
JSON.parseObject("{\"value\":null}", VO.class);
15+
}
16+
17+
public void test_strNull() throws Exception {
18+
JSON.parseObject("{\"value\":\"null\"}", VO.class);
19+
}
20+
21+
public static class VO {
22+
23+
private float value;
24+
25+
public float getValue() {
26+
return value;
27+
}
28+
29+
public void setValue(float value) {
30+
throw new UnsupportedOperationException();
31+
}
32+
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.alibaba.json.bvt.bug;
2+
3+
import junit.framework.TestCase;
4+
5+
import com.alibaba.fastjson.JSON;
6+
7+
public class Bug_for_primitive_int extends TestCase {
8+
9+
public void test_emptyStr() throws Exception {
10+
JSON.parseObject("{\"value\":\"\"}", VO.class);
11+
}
12+
13+
public void test_null() throws Exception {
14+
JSON.parseObject("{\"value\":null}", VO.class);
15+
}
16+
17+
public void test_strNull() throws Exception {
18+
JSON.parseObject("{\"value\":\"null\"}", VO.class);
19+
}
20+
21+
public static class VO {
22+
23+
private int value;
24+
25+
public int getValue() {
26+
return value;
27+
}
28+
29+
public void setValue(int value) {
30+
throw new UnsupportedOperationException();
31+
}
32+
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.alibaba.json.bvt.bug;
2+
3+
import junit.framework.TestCase;
4+
5+
import com.alibaba.fastjson.JSON;
6+
7+
public class Bug_for_primitive_long extends TestCase {
8+
9+
public void test_emptyStr() throws Exception {
10+
JSON.parseObject("{\"value\":\"\"}", VO.class);
11+
}
12+
13+
public void test_null() throws Exception {
14+
JSON.parseObject("{\"value\":null}", VO.class);
15+
}
16+
17+
public void test_strNull() throws Exception {
18+
JSON.parseObject("{\"value\":\"null\"}", VO.class);
19+
}
20+
21+
public static class VO {
22+
23+
private long value;
24+
25+
public long getValue() {
26+
return value;
27+
}
28+
29+
public void setValue(long value) {
30+
throw new UnsupportedOperationException();
31+
}
32+
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.alibaba.json.bvt.bug;
2+
3+
import junit.framework.TestCase;
4+
5+
import com.alibaba.fastjson.JSON;
6+
7+
public class Bug_for_primitive_short extends TestCase {
8+
9+
public void test_emptyStr() throws Exception {
10+
JSON.parseObject("{\"value\":\"\"}", VO.class);
11+
}
12+
13+
public void test_null() throws Exception {
14+
JSON.parseObject("{\"value\":null}", VO.class);
15+
}
16+
17+
public void test_strNull() throws Exception {
18+
JSON.parseObject("{\"value\":\"null\"}", VO.class);
19+
}
20+
21+
public static class VO {
22+
23+
private short value;
24+
25+
public short getValue() {
26+
return value;
27+
}
28+
29+
public void setValue(short value) {
30+
throw new UnsupportedOperationException();
31+
}
32+
33+
}
34+
}

0 commit comments

Comments
 (0)