Skip to content

Commit e971ac0

Browse files
committed
add blackbox test
1 parent 1b5847c commit e971ac0

File tree

5 files changed

+66
-36
lines changed

5 files changed

+66
-36
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.example.customer.mixin;
2+
3+
public class CrewMate {
4+
5+
private String c;
6+
private Integer susLv;
7+
8+
public CrewMate(String c, Integer susLv) {
9+
this.c = c;
10+
this.susLv = susLv;
11+
}
12+
13+
public String getC() {
14+
return c;
15+
}
16+
17+
public void setC(String c) {
18+
this.c = c;
19+
}
20+
21+
public Integer getSusLv() {
22+
return susLv;
23+
}
24+
25+
public void setSusLv(Integer susLv) {
26+
this.susLv = susLv;
27+
}
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.example.customer.mixin;
2+
3+
import io.avaje.jsonb.Json;
4+
5+
@Json.Import(CrewMate.class)
6+
@Json.MixIn(CrewMate.class)
7+
public abstract class CrewMateMixIn {
8+
9+
@Json.Property("color")
10+
private String c;
11+
12+
@Json.Ignore(deserialize = true)
13+
private int susLv;
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.example.customer.mixin;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import io.avaje.jsonb.Jsonb;
8+
9+
class MixinTest {
10+
11+
Jsonb jsonb = Jsonb.builder().build();
12+
13+
@Test
14+
void toJsonFromJson() {
15+
final var bean = new CrewMate("red", 999);
16+
17+
final var asJson = jsonb.toJson(bean);
18+
assertThat(asJson).isEqualTo("{\"color\":\"red\"}");
19+
20+
final var fromJson = jsonb.type(CrewMate.class).fromJson("{\"color\":\"blue\",\"susLv\":\"0\"}");
21+
assertThat(fromJson.getC()).isEqualTo("blue");
22+
assertThat(fromJson.getSusLv()).isZero();
23+
}
24+
}

jsonb-generator/src/test/java/io/avaje/jsonb/generator/models/valid/MixinClass.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

jsonb-generator/src/test/java/io/avaje/jsonb/generator/models/valid/MixinTarget.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)