-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fix jsonb deserialize error on null list field ,for issue #2181
- Loading branch information
Showing
3 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
core/src/test/java/com/alibaba/fastjson2/issues_2100/Issue2181.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.alibaba.fastjson2.issues_2100; | ||
|
||
import com.alibaba.fastjson2.JSONB; | ||
import com.alibaba.fastjson2.JSONReader; | ||
import com.alibaba.fastjson2.JSONWriter; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import org.apache.dubbo.common.serialize.fastjson2.FastJson2ObjectInput; | ||
import org.apache.dubbo.common.serialize.fastjson2.FastJson2ObjectOutput; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* @author 张治保 | ||
* @since 2024/1/15 | ||
*/ | ||
public class Issue2181 { | ||
@ToString | ||
@Getter | ||
@Setter | ||
public static class CommonException extends RuntimeException { | ||
Integer code; | ||
String message; | ||
List params; | ||
|
||
public CommonException(Integer code, String message) { | ||
// super(message); | ||
this.message = message; | ||
this.code = code; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @see FastJson2ObjectOutput#writeObject(Object) | ||
* @see FastJson2ObjectInput#readObject(Class) | ||
*/ | ||
@Test | ||
void test() { | ||
//writeObject | ||
CommonException error = new CommonException(1, "error"); | ||
byte[] bytes = JSONB.toBytes( | ||
error, | ||
JSONWriter.Feature.WriteClassName, | ||
JSONWriter.Feature.FieldBased, | ||
JSONWriter.Feature.ErrorOnNoneSerializable, | ||
JSONWriter.Feature.ReferenceDetection, | ||
JSONWriter.Feature.WriteNulls, | ||
JSONWriter.Feature.NotWriteDefaultValue, | ||
JSONWriter.Feature.NotWriteHashMapArrayListClassName, | ||
JSONWriter.Feature.WriteNameAsSymbol); | ||
// readObject | ||
Object result = JSONB.parseObject( | ||
bytes, | ||
Exception.class, | ||
JSONReader.autoTypeFilter(true, CommonException.class), | ||
JSONReader.Feature.UseDefaultConstructorAsPossible, | ||
JSONReader.Feature.ErrorOnNoneSerializable, | ||
JSONReader.Feature.IgnoreAutoTypeNotMatch, | ||
JSONReader.Feature.UseNativeObject, | ||
JSONReader.Feature.FieldBased); | ||
assertNotNull(result); | ||
assertSame(result.getClass(), CommonException.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters