-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve mixin non-getter annotation match, for issue #1474
- Loading branch information
Showing
4 changed files
with
114 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
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
85 changes: 85 additions & 0 deletions
85
core/src/test/java/com/alibaba/fastjson2/issues_1000/Issue1474.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,85 @@ | ||
package com.alibaba.fastjson2.issues_1000; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONWriter; | ||
import com.alibaba.fastjson2.annotation.JSONField; | ||
import com.alibaba.fastjson2.annotation.JSONType; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue1474 { | ||
@Test | ||
public void test() { | ||
JSON.mixIn(ProducerRecord.class, ProducerRecordMixin.class); | ||
|
||
ProducerRecord record = new ProducerRecord("abc"); | ||
assertEquals("{\"topic\":\"abc\"}", JSON.toJSONString(record)); | ||
} | ||
|
||
public interface ProducerRecordMixin { | ||
@JSONField | ||
String topic(); | ||
} | ||
|
||
public static class ProducerRecord { | ||
private final String topic; | ||
|
||
public ProducerRecord(String topic) { | ||
this.topic = topic; | ||
} | ||
|
||
public String topic() { | ||
return topic; | ||
} | ||
} | ||
|
||
@Test | ||
public void test1() { | ||
JSON.mixIn(ProducerRecord1.class, ProducerRecordMixin1.class); | ||
|
||
ProducerRecord1 record = new ProducerRecord1("abc"); | ||
assertEquals("{\"topic\":\"abc\"}", JSON.toJSONString(record)); | ||
} | ||
|
||
@JSONType(serializeFeatures = JSONWriter.Feature.FieldBased) | ||
public interface ProducerRecordMixin1 { | ||
} | ||
|
||
public static class ProducerRecord1 { | ||
private final String topic; | ||
|
||
public ProducerRecord1(String topic) { | ||
this.topic = topic; | ||
} | ||
|
||
public String topic() { | ||
return topic; | ||
} | ||
} | ||
|
||
@Test | ||
public void test2() { | ||
JSON.mixIn(ProducerRecord2.class, ProducerRecordMixin2.class); | ||
|
||
ProducerRecord2 record = new ProducerRecord2("abc"); | ||
assertEquals("{\"topic\":\"abc\"}", JSON.toJSONString(record)); | ||
} | ||
|
||
public interface ProducerRecordMixin2 { | ||
@JSONField | ||
String topic(); | ||
} | ||
|
||
static class ProducerRecord2 { | ||
private final String topic; | ||
|
||
public ProducerRecord2(String topic) { | ||
this.topic = topic; | ||
} | ||
|
||
public String topic() { | ||
return topic; | ||
} | ||
} | ||
} |