-
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.
fix prefer to most specified setter method, for issue #2229
- Loading branch information
1 parent
7118a55
commit 47088a6
Showing
3 changed files
with
90 additions
and
13 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
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
52 changes: 52 additions & 0 deletions
52
core/src/test/java/com/alibaba/fastjson2/issues_2200/Issue2229.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,52 @@ | ||
package com.alibaba.fastjson2.issues_2200; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue2229 { | ||
@Test | ||
void test() { | ||
String json = "{\"type\": \"A\", \"types\": [\"B\"]}"; | ||
DTO dto = JSON.parseObject(json, DTO.class); | ||
assertEquals(Type.A, dto.getType()); | ||
assertEquals(Type.B, dto.getTypes().get(0)); | ||
} | ||
|
||
static class DTO { | ||
private Type type; | ||
private List<Type> types; | ||
|
||
public Type getType() { | ||
return type; | ||
} | ||
|
||
public void setType(Type type) { | ||
this.type = type; | ||
} | ||
|
||
public void setType(int type) { | ||
this.type = null; | ||
} | ||
|
||
public List<Type> getTypes() { | ||
return types; | ||
} | ||
|
||
public void setTypes(List<Type> types) { | ||
this.types = types; | ||
} | ||
|
||
public void setTypes(int types) { | ||
this.types = new ArrayList<>(); | ||
} | ||
} | ||
|
||
enum Type { | ||
A,B; | ||
} | ||
} |