Skip to content

Commit 19ac640

Browse files
committed
MyBatis result classes need Nullable fields
1 parent acf0dc5 commit 19ac640

File tree

7 files changed

+62
-49
lines changed

7 files changed

+62
-49
lines changed

src/test/java/examples/array/NamesRecord.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@
1515
*/
1616
package examples.array;
1717

18+
import org.jspecify.annotations.Nullable;
19+
1820
public class NamesRecord {
19-
private Integer id;
20-
private String[] names;
21+
private @Nullable Integer id;
22+
private @Nullable String[] names;
2123

22-
public Integer getId() {
24+
public @Nullable Integer getId() {
2325
return id;
2426
}
2527

2628
public void setId(Integer id) {
2729
this.id = id;
2830
}
2931

30-
public String[] getNames() {
32+
public @Nullable String[] getNames() {
3133
return names;
3234
}
3335

src/test/java/examples/generated/always/mybatis/GeneratedKey.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
*/
1616
package examples.generated.always.mybatis;
1717

18+
import org.jspecify.annotations.Nullable;
19+
1820
public class GeneratedKey {
1921

20-
private Integer key;
22+
private @Nullable Integer key;
2123

22-
public Integer getKey() {
24+
public @Nullable Integer getKey() {
2325
return key;
2426
}
2527

src/test/java/examples/joins/OrderMaster.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,30 @@
1818
import java.util.Date;
1919
import java.util.List;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
public class OrderMaster {
22-
private Integer id;
23-
private Date orderDate;
24-
private List<OrderDetail> details;
24+
private @Nullable Integer id;
25+
private @Nullable Date orderDate;
26+
private @Nullable List<OrderDetail> details;
2527

26-
public Integer getId() {
28+
public @Nullable Integer getId() {
2729
return id;
2830
}
2931

3032
public void setId(Integer id) {
3133
this.id = id;
3234
}
3335

34-
public Date getOrderDate() {
36+
public @Nullable Date getOrderDate() {
3537
return orderDate;
3638
}
3739

3840
public void setOrderDate(Date orderDate) {
3941
this.orderDate = orderDate;
4042
}
4143

42-
public List<OrderDetail> getDetails() {
44+
public @Nullable List<OrderDetail> getDetails() {
4345
return details;
4446
}
4547

src/test/java/examples/simple/AddressRecord.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,48 @@
1515
*/
1616
package examples.simple;
1717

18+
import org.jspecify.annotations.Nullable;
19+
1820
public class AddressRecord {
19-
private Integer id;
20-
private String streetAddress;
21-
private String city;
22-
private String state;
23-
private AddressType addressType;
21+
private @Nullable Integer id;
22+
private @Nullable String streetAddress;
23+
private @Nullable String city;
24+
private @Nullable String state;
25+
private @Nullable AddressType addressType;
2426

25-
public Integer getId() {
27+
public @Nullable Integer getId() {
2628
return id;
2729
}
2830

2931
public void setId(Integer id) {
3032
this.id = id;
3133
}
3234

33-
public String getStreetAddress() {
35+
public @Nullable String getStreetAddress() {
3436
return streetAddress;
3537
}
3638

3739
public void setStreetAddress(String streetAddress) {
3840
this.streetAddress = streetAddress;
3941
}
4042

41-
public String getCity() {
43+
public @Nullable String getCity() {
4244
return city;
4345
}
4446

4547
public void setCity(String city) {
4648
this.city = city;
4749
}
4850

49-
public String getState() {
51+
public @Nullable String getState() {
5052
return state;
5153
}
5254

5355
public void setState(String state) {
5456
this.state = state;
5557
}
5658

57-
public AddressType getAddressType() {
59+
public @Nullable AddressType getAddressType() {
5860
return addressType;
5961
}
6062

src/test/java/examples/simple/PersonWithAddress.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,66 +15,68 @@
1515
*/
1616
package examples.simple;
1717

18+
import org.jspecify.annotations.Nullable;
19+
1820
import java.util.Date;
1921

2022
public class PersonWithAddress {
21-
private Integer id;
22-
private String firstName;
23-
private LastName lastName;
24-
private Date birthDate;
25-
private Boolean employed;
26-
private String occupation;
27-
private AddressRecord address;
28-
29-
public Integer getId() {
23+
private @Nullable Integer id;
24+
private @Nullable String firstName;
25+
private @Nullable LastName lastName;
26+
private @Nullable Date birthDate;
27+
private @Nullable Boolean employed;
28+
private @Nullable String occupation;
29+
private @Nullable AddressRecord address;
30+
31+
public @Nullable Integer getId() {
3032
return id;
3133
}
3234

3335
public void setId(Integer id) {
3436
this.id = id;
3537
}
3638

37-
public String getFirstName() {
39+
public @Nullable String getFirstName() {
3840
return firstName;
3941
}
4042

4143
public void setFirstName(String firstName) {
4244
this.firstName = firstName;
4345
}
4446

45-
public LastName getLastName() {
47+
public @Nullable LastName getLastName() {
4648
return lastName;
4749
}
4850

4951
public void setLastName(LastName lastName) {
5052
this.lastName = lastName;
5153
}
5254

53-
public Date getBirthDate() {
55+
public @Nullable Date getBirthDate() {
5456
return birthDate;
5557
}
5658

5759
public void setBirthDate(Date birthDate) {
5860
this.birthDate = birthDate;
5961
}
6062

61-
public String getOccupation() {
63+
public @Nullable String getOccupation() {
6264
return occupation;
6365
}
6466

6567
public void setOccupation(String occupation) {
6668
this.occupation = occupation;
6769
}
6870

69-
public Boolean getEmployed() {
71+
public @Nullable Boolean getEmployed() {
7072
return employed;
7173
}
7274

7375
public void setEmployed(Boolean employed) {
7476
this.employed = employed;
7577
}
7678

77-
public AddressRecord getAddress() {
79+
public @Nullable AddressRecord getAddress() {
7880
return address;
7981
}
8082

src/test/java/issues/gh324/NameRecord.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@
1515
*/
1616
package issues.gh324;
1717

18+
import org.jspecify.annotations.Nullable;
19+
1820
import java.io.Serializable;
1921

2022
public class NameRecord implements Serializable {
21-
private Integer id;
22-
private String name;
23+
private @Nullable Integer id;
24+
private @Nullable String name;
2325

24-
public Integer getId() {
26+
public @Nullable Integer getId() {
2527
return id;
2628
}
2729

2830
public void setId(Integer id) {
2931
this.id = id;
3032
}
3133

32-
public String getName() {
34+
public @Nullable String getName() {
3335
return name;
3436
}
3537

src/test/java/org/mybatis/dynamic/sql/mybatis3/InsertStatementTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.sql.JDBCType;
2222

23+
import org.jspecify.annotations.Nullable;
2324
import org.junit.jupiter.api.Test;
2425
import org.mybatis.dynamic.sql.SqlColumn;
2526
import org.mybatis.dynamic.sql.SqlTable;
@@ -77,36 +78,36 @@ void testSelectiveInsertStatementBuilder() {
7778
}
7879

7980
static class TestRecord {
80-
private Integer id;
81-
private String firstName;
82-
private String lastName;
83-
private String occupation;
81+
private @Nullable Integer id;
82+
private @Nullable String firstName;
83+
private @Nullable String lastName;
84+
private @Nullable String occupation;
8485

85-
Integer getId() {
86+
@Nullable Integer getId() {
8687
return id;
8788
}
8889

8990
void setId(Integer id) {
9091
this.id = id;
9192
}
9293

93-
String getFirstName() {
94+
@Nullable String getFirstName() {
9495
return firstName;
9596
}
9697

9798
void setFirstName(String firstName) {
9899
this.firstName = firstName;
99100
}
100101

101-
String getLastName() {
102+
@Nullable String getLastName() {
102103
return lastName;
103104
}
104105

105106
void setLastName(String lastName) {
106107
this.lastName = lastName;
107108
}
108109

109-
String getOccupation() {
110+
@Nullable String getOccupation() {
110111
return occupation;
111112
}
112113

0 commit comments

Comments
 (0)