This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
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.
- Loading branch information
Showing
3 changed files
with
76 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
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
62 changes: 62 additions & 0 deletions
62
src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_457.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,62 @@ | ||
package com.alibaba.json.bvt.bug; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.parser.DefaultJSONParser; | ||
import com.alibaba.fastjson.parser.JSONToken; | ||
import com.alibaba.fastjson.parser.ParserConfig; | ||
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class Bug_for_issue_457 extends TestCase { | ||
|
||
public void test_for_issue() throws Exception { | ||
ParserConfig.global.putDeserializer(MyEnum.class, new MyEnumDeser()); | ||
VO entity = JSON.parseObject("{\"myEnum\":\"AA\"}", VO.class); | ||
Assert.assertEquals(MyEnum.A, entity.myEnum); | ||
} | ||
|
||
public static class MyEnumDeser implements ObjectDeserializer { | ||
|
||
@Override | ||
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { | ||
String text = (String) parser.parse(); | ||
if (text.equals("AA")) { | ||
return (T) MyEnum.A; | ||
} | ||
|
||
if (text.equals("BB")) { | ||
return (T) MyEnum.B; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getFastMatchToken() { | ||
return JSONToken.LITERAL_STRING; | ||
} | ||
|
||
} | ||
|
||
|
||
public static class VO { | ||
|
||
private MyEnum myEnum; | ||
|
||
public void setMyEnum(MyEnum myEnum) { | ||
this.myEnum = myEnum; | ||
} | ||
|
||
public MyEnum getMyEnum() { | ||
return myEnum; | ||
} | ||
} | ||
|
||
public static enum MyEnum { | ||
A, B | ||
} | ||
} |