-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3475 from akiyamaneko/AfterFilter-NullPointerExce…
…ption fix AfterFilter NullPointer exception in #3443
- Loading branch information
Showing
2 changed files
with
60 additions
and
2 deletions.
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
58 changes: 58 additions & 0 deletions
58
src/test/java/com/alibaba/json/bvt/issue_3300/Issue3443.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,58 @@ | ||
package com.alibaba.json.bvt.issue_3300; | ||
|
||
import com.alibaba.fastjson.serializer.*; | ||
import junit.framework.TestCase; | ||
|
||
public class Issue3443 extends TestCase { | ||
public void testCustomJsonSerializerAndAfterFilter() throws Exception { | ||
SerializeWriter serializeWriter = new SerializeWriter(); | ||
try { | ||
JSONSerializer jsonSerializer = new JSONSerializer(serializeWriter, new SerializeConfig()); | ||
|
||
Parameter parameter = new Parameter(); | ||
parameter.setParameterDesc(new ParameterDesc("vipExpireDate", "VIP expire date.")); | ||
|
||
jsonSerializer.config(SerializerFeature.DisableCircularReferenceDetect, true); | ||
jsonSerializer.getAfterFilters().add(new CustomFilter()); | ||
jsonSerializer.write(parameter); | ||
assertEquals("{\"parameterDesc\":{\"ParameterDesc\":\"VIP expire date.\"}}", serializeWriter.toString()); | ||
} finally { | ||
serializeWriter.close(); | ||
} | ||
} | ||
|
||
static class Parameter { | ||
private ParameterDesc parameterDesc; | ||
|
||
public ParameterDesc getParameterDesc() { | ||
return parameterDesc; | ||
} | ||
|
||
public void setParameterDesc(ParameterDesc parameterType) { | ||
this.parameterDesc = parameterType; | ||
} | ||
} | ||
|
||
static class ParameterDesc { | ||
private String parameterName; | ||
private String parameterUsage; | ||
// do some work... | ||
|
||
public ParameterDesc(String parameterName, String parameterUsage) { | ||
this.parameterName = parameterName; | ||
this.parameterUsage = parameterUsage; | ||
} | ||
|
||
|
||
} | ||
|
||
static class CustomFilter extends AfterFilter { | ||
|
||
@Override | ||
public void writeAfter(Object object) { | ||
if (object instanceof ParameterDesc) { | ||
writeKeyValue("ParameterDesc", "VIP expire date."); | ||
} | ||
} | ||
} | ||
} |