File tree 3 files changed +5
-9
lines changed
main/java/com/tencent/trpc/core/utils
test/java/com/tencent/trpc/core
3 files changed +5
-9
lines changed Original file line number Diff line number Diff line change 16
16
import com .fasterxml .jackson .databind .DeserializationFeature ;
17
17
import com .fasterxml .jackson .databind .JavaType ;
18
18
import com .fasterxml .jackson .databind .ObjectMapper ;
19
+ import com .fasterxml .jackson .databind .SerializationFeature ;
19
20
import com .tencent .trpc .core .exception .ErrorCode ;
20
21
import com .tencent .trpc .core .exception .TRpcException ;
21
22
import com .tencent .trpc .core .logger .Logger ;
@@ -39,6 +40,8 @@ public class JsonUtils {
39
40
objectMapper .setSerializationInclusion (Include .NON_NULL );
40
41
// Do not throw an error when deserializing if there are no corresponding properties
41
42
objectMapper .disable (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES );
43
+ // Do not throw an error when serializing if there are no public fields
44
+ objectMapper .disable (SerializationFeature .FAIL_ON_EMPTY_BEANS );
42
45
}
43
46
44
47
/**
Original file line number Diff line number Diff line change @@ -61,14 +61,6 @@ public void testJson2Pojo() {
61
61
*/
62
62
@ Test
63
63
public void testJson2PojoEx () {
64
- try {
65
- JsonUtilsTest .TestObj1 obj1 = new JsonUtilsTest .TestObj1 ();
66
- obj1 .setTest (123 );
67
- serial .serialize (obj1 );
68
- Assert .fail ();
69
- } catch (Exception e ) {
70
- Assert .assertTrue (e .getMessage ().contains ("json serialize ex:" ));
71
- }
72
64
try {
73
65
byte [] bytes = serial .serialize (obj );
74
66
GenericsObj deserialize = serial .deserialize (bytes , GenericsObj .class );
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ public class JsonUtilsTest {
32
32
private static final String JSON = "{\" test\" :123}" ;
33
33
private static final String JSON_LIST = "[{\" test\" :123},{\" test\" :123}]" ;
34
34
private static final String ERROR_JSON = "{\" test\" :123,A}" ;
35
+ private static final String EMPTY_JSON = "{}" ;
35
36
36
37
@ Test
37
38
public void testCopy () {
@@ -134,7 +135,7 @@ public void testToJsonWithDefaultValue() {
134
135
TestObj1 obj1 = new TestObj1 ();
135
136
obj1 .setTest (123 );
136
137
String aaa = JsonUtils .toJson (obj1 , "aaa" );
137
- Assert .assertEquals ("aaa" , aaa );
138
+ Assert .assertEquals (EMPTY_JSON , aaa );
138
139
}
139
140
140
141
@ Test
You can’t perform that action at this time.
0 commit comments