Skip to content

Commit f9065aa

Browse files
oschwaldclaude
andcommitted
Remove most uses of @MaxMindDbConstructor
With maxmind-db 4.0.0, records automatically use their canonical constructor for deserialization when no constructor is explicitly annotated with @MaxMindDbConstructor. This change removes the annotation from most records in the codebase. Changes: - Removed empty canonical constructors from records with no logic - Removed @MaxMindDbConstructor from canonical constructors with immutability/validation logic, relying on automatic detection - Added useDefault=true to boolean parameters to leverage automatic null-to-false conversion instead of manual Boolean→boolean handling - Kept @MaxMindDbConstructor only for records requiring custom type conversions (String→LocalDate in AnonymousPlusResponse, String→enum in ConnectionTypeResponse and Traits) - Removed unused MaxMindDbConstructor imports All tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 36bfdba commit f9065aa

18 files changed

+78
-279
lines changed

src/main/java/com/maxmind/geoip2/model/AnonymousIpResponse.java

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
66
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
77
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
8-
import com.maxmind.db.MaxMindDbConstructor;
98
import com.maxmind.db.MaxMindDbParameter;
109
import com.maxmind.db.Network;
1110
import com.maxmind.geoip2.JsonSerializable;
@@ -34,27 +33,27 @@ public record AnonymousIpResponse(
3433
String ipAddress,
3534

3635
@JsonProperty("is_anonymous")
37-
@MaxMindDbParameter(name = "is_anonymous")
36+
@MaxMindDbParameter(name = "is_anonymous", useDefault = true)
3837
boolean isAnonymous,
3938

4039
@JsonProperty("is_anonymous_vpn")
41-
@MaxMindDbParameter(name = "is_anonymous_vpn")
40+
@MaxMindDbParameter(name = "is_anonymous_vpn", useDefault = true)
4241
boolean isAnonymousVpn,
4342

4443
@JsonProperty("is_hosting_provider")
45-
@MaxMindDbParameter(name = "is_hosting_provider")
44+
@MaxMindDbParameter(name = "is_hosting_provider", useDefault = true)
4645
boolean isHostingProvider,
4746

4847
@JsonProperty("is_public_proxy")
49-
@MaxMindDbParameter(name = "is_public_proxy")
48+
@MaxMindDbParameter(name = "is_public_proxy", useDefault = true)
5049
boolean isPublicProxy,
5150

5251
@JsonProperty("is_residential_proxy")
53-
@MaxMindDbParameter(name = "is_residential_proxy")
52+
@MaxMindDbParameter(name = "is_residential_proxy", useDefault = true)
5453
boolean isResidentialProxy,
5554

5655
@JsonProperty("is_tor_exit_node")
57-
@MaxMindDbParameter(name = "is_tor_exit_node")
56+
@MaxMindDbParameter(name = "is_tor_exit_node", useDefault = true)
5857
boolean isTorExitNode,
5958

6059
@JsonProperty("network")
@@ -63,41 +62,6 @@ public record AnonymousIpResponse(
6362
Network network
6463
) implements JsonSerializable {
6564

66-
/**
67-
* Constructs an instance of {@code AnonymousIpResponse} with nullable boolean fields.
68-
*
69-
* @param ipAddress the IP address being checked
70-
* @param isAnonymous whether the IP address belongs to any sort of anonymous network
71-
* @param isAnonymousVpn whether the IP address belongs to an anonymous VPN system
72-
* @param isHostingProvider whether the IP address belongs to a hosting provider
73-
* @param isPublicProxy whether the IP address belongs to a public proxy system
74-
* @param isResidentialProxy whether the IP address belongs to a residential proxy system
75-
* @param isTorExitNode whether the IP address is a Tor exit node
76-
* @param network the network associated with the record
77-
*/
78-
@MaxMindDbConstructor
79-
public AnonymousIpResponse(
80-
@MaxMindDbParameter(name = "ip_address") String ipAddress,
81-
@MaxMindDbParameter(name = "is_anonymous") Boolean isAnonymous,
82-
@MaxMindDbParameter(name = "is_anonymous_vpn") Boolean isAnonymousVpn,
83-
@MaxMindDbParameter(name = "is_hosting_provider") Boolean isHostingProvider,
84-
@MaxMindDbParameter(name = "is_public_proxy") Boolean isPublicProxy,
85-
@MaxMindDbParameter(name = "is_residential_proxy") Boolean isResidentialProxy,
86-
@MaxMindDbParameter(name = "is_tor_exit_node") Boolean isTorExitNode,
87-
@MaxMindDbParameter(name = "network") Network network
88-
) {
89-
this(
90-
ipAddress,
91-
isAnonymous != null ? isAnonymous : false,
92-
isAnonymousVpn != null ? isAnonymousVpn : false,
93-
isHostingProvider != null ? isHostingProvider : false,
94-
isPublicProxy != null ? isPublicProxy : false,
95-
isResidentialProxy != null ? isResidentialProxy : false,
96-
isTorExitNode != null ? isTorExitNode : false,
97-
network
98-
);
99-
}
100-
10165
/**
10266
* Constructs an instance of {@code AnonymousIpResponse} from the values in the passed
10367
* response and the specified IP address and network.

src/main/java/com/maxmind/geoip2/model/AnonymousPlusResponse.java

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,27 @@ public record AnonymousPlusResponse(
4141
String ipAddress,
4242

4343
@JsonProperty("is_anonymous")
44-
@MaxMindDbParameter(name = "is_anonymous")
44+
@MaxMindDbParameter(name = "is_anonymous", useDefault = true)
4545
boolean isAnonymous,
4646

4747
@JsonProperty("is_anonymous_vpn")
48-
@MaxMindDbParameter(name = "is_anonymous_vpn")
48+
@MaxMindDbParameter(name = "is_anonymous_vpn", useDefault = true)
4949
boolean isAnonymousVpn,
5050

5151
@JsonProperty("is_hosting_provider")
52-
@MaxMindDbParameter(name = "is_hosting_provider")
52+
@MaxMindDbParameter(name = "is_hosting_provider", useDefault = true)
5353
boolean isHostingProvider,
5454

5555
@JsonProperty("is_public_proxy")
56-
@MaxMindDbParameter(name = "is_public_proxy")
56+
@MaxMindDbParameter(name = "is_public_proxy", useDefault = true)
5757
boolean isPublicProxy,
5858

5959
@JsonProperty("is_residential_proxy")
60-
@MaxMindDbParameter(name = "is_residential_proxy")
60+
@MaxMindDbParameter(name = "is_residential_proxy", useDefault = true)
6161
boolean isResidentialProxy,
6262

6363
@JsonProperty("is_tor_exit_node")
64-
@MaxMindDbParameter(name = "is_tor_exit_node")
64+
@MaxMindDbParameter(name = "is_tor_exit_node", useDefault = true)
6565
boolean isTorExitNode,
6666

6767
@JsonProperty("network")
@@ -83,10 +83,9 @@ public record AnonymousPlusResponse(
8383
) implements JsonSerializable {
8484

8585
/**
86-
* Constructs an instance of {@code AnonymousPlusResponse} with nullable boolean fields
87-
* and date parsing from MaxMind database.
86+
* Constructs an instance of {@code AnonymousPlusResponse} with date parsing
87+
* from MaxMind database.
8888
*
89-
* @param anonymizerConfidence confidence that the network is a VPN.
9089
* @param ipAddress the IP address being checked
9190
* @param isAnonymous whether the IP address belongs to any sort of anonymous network
9291
* @param isAnonymousVpn whether the IP address belongs to an anonymous VPN system
@@ -95,31 +94,38 @@ public record AnonymousPlusResponse(
9594
* @param isResidentialProxy whether the IP address belongs to a residential proxy system
9695
* @param isTorExitNode whether the IP address is a Tor exit node
9796
* @param network the network associated with the record
97+
* @param anonymizerConfidence confidence that the network is a VPN.
9898
* @param networkLastSeen the last sighting of the network.
9999
* @param providerName the name of the VPN provider.
100100
*/
101101
@MaxMindDbConstructor
102102
public AnonymousPlusResponse(
103-
@MaxMindDbParameter(name = "anonymizer_confidence") Integer anonymizerConfidence,
104103
@MaxMindDbParameter(name = "ip_address") String ipAddress,
105-
@MaxMindDbParameter(name = "is_anonymous") Boolean isAnonymous,
106-
@MaxMindDbParameter(name = "is_anonymous_vpn") Boolean isAnonymousVpn,
107-
@MaxMindDbParameter(name = "is_hosting_provider") Boolean isHostingProvider,
108-
@MaxMindDbParameter(name = "is_public_proxy") Boolean isPublicProxy,
109-
@MaxMindDbParameter(name = "is_residential_proxy") Boolean isResidentialProxy,
110-
@MaxMindDbParameter(name = "is_tor_exit_node") Boolean isTorExitNode,
104+
@MaxMindDbParameter(name = "is_anonymous", useDefault = true)
105+
boolean isAnonymous,
106+
@MaxMindDbParameter(name = "is_anonymous_vpn", useDefault = true)
107+
boolean isAnonymousVpn,
108+
@MaxMindDbParameter(name = "is_hosting_provider", useDefault = true)
109+
boolean isHostingProvider,
110+
@MaxMindDbParameter(name = "is_public_proxy", useDefault = true)
111+
boolean isPublicProxy,
112+
@MaxMindDbParameter(name = "is_residential_proxy", useDefault = true)
113+
boolean isResidentialProxy,
114+
@MaxMindDbParameter(name = "is_tor_exit_node", useDefault = true)
115+
boolean isTorExitNode,
111116
@MaxMindDbParameter(name = "network") Network network,
117+
@MaxMindDbParameter(name = "anonymizer_confidence") Integer anonymizerConfidence,
112118
@MaxMindDbParameter(name = "network_last_seen") String networkLastSeen,
113119
@MaxMindDbParameter(name = "provider_name") String providerName
114120
) {
115121
this(
116122
ipAddress,
117-
isAnonymous != null ? isAnonymous : false,
118-
isAnonymousVpn != null ? isAnonymousVpn : false,
119-
isHostingProvider != null ? isHostingProvider : false,
120-
isPublicProxy != null ? isPublicProxy : false,
121-
isResidentialProxy != null ? isResidentialProxy : false,
122-
isTorExitNode != null ? isTorExitNode : false,
123+
isAnonymous,
124+
isAnonymousVpn,
125+
isHostingProvider,
126+
isPublicProxy,
127+
isResidentialProxy,
128+
isTorExitNode,
123129
network,
124130
anonymizerConfidence,
125131
networkLastSeen != null ? LocalDate.parse(networkLastSeen) : null,

src/main/java/com/maxmind/geoip2/model/AsnResponse.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
66
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
77
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
8-
import com.maxmind.db.MaxMindDbConstructor;
98
import com.maxmind.db.MaxMindDbParameter;
109
import com.maxmind.db.Network;
1110
import com.maxmind.geoip2.JsonSerializable;
@@ -40,13 +39,6 @@ public record AsnResponse(
4039
Network network
4140
) implements JsonSerializable {
4241

43-
/**
44-
* Canonical constructor.
45-
*/
46-
@MaxMindDbConstructor
47-
public AsnResponse {
48-
}
49-
5042
/**
5143
* Constructs an instance of {@code AsnResponse} with only the specified values set.
5244
*

src/main/java/com/maxmind/geoip2/model/CityResponse.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.fasterxml.jackson.annotation.JacksonInject;
44
import com.fasterxml.jackson.annotation.JsonIgnore;
55
import com.fasterxml.jackson.annotation.JsonProperty;
6-
import com.maxmind.db.MaxMindDbConstructor;
76
import com.maxmind.db.MaxMindDbParameter;
87
import com.maxmind.db.Network;
98
import com.maxmind.geoip2.JsonSerializable;
@@ -91,7 +90,6 @@ public record CityResponse(
9190
/**
9291
* Compact canonical constructor that sets defaults for null values.
9392
*/
94-
@MaxMindDbConstructor
9593
public CityResponse {
9694
city = city != null ? city : new City();
9795
continent = continent != null ? continent : new Continent();

src/main/java/com/maxmind/geoip2/model/CountryResponse.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.fasterxml.jackson.annotation.JacksonInject;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5-
import com.maxmind.db.MaxMindDbConstructor;
65
import com.maxmind.db.MaxMindDbParameter;
76
import com.maxmind.db.Network;
87
import com.maxmind.geoip2.JsonSerializable;
@@ -60,7 +59,6 @@ public record CountryResponse(
6059
/**
6160
* Compact canonical constructor that sets defaults for null values.
6261
*/
63-
@MaxMindDbConstructor
6462
public CountryResponse {
6563
continent = continent != null ? continent : new Continent();
6664
country = country != null ? country : new Country();

src/main/java/com/maxmind/geoip2/model/DomainResponse.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
66
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
77
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
8-
import com.maxmind.db.MaxMindDbConstructor;
98
import com.maxmind.db.MaxMindDbParameter;
109
import com.maxmind.db.Network;
1110
import com.maxmind.geoip2.JsonSerializable;
@@ -35,13 +34,6 @@ public record DomainResponse(
3534
Network network
3635
) implements JsonSerializable {
3736

38-
/**
39-
* Canonical constructor.
40-
*/
41-
@MaxMindDbConstructor
42-
public DomainResponse {
43-
}
44-
4537
/**
4638
* Constructs an instance of {@code DomainResponse} with only required parameters.
4739
*

src/main/java/com/maxmind/geoip2/model/EnterpriseResponse.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.fasterxml.jackson.annotation.JacksonInject;
44
import com.fasterxml.jackson.annotation.JsonIgnore;
55
import com.fasterxml.jackson.annotation.JsonProperty;
6-
import com.maxmind.db.MaxMindDbConstructor;
76
import com.maxmind.db.MaxMindDbParameter;
87
import com.maxmind.db.Network;
98
import com.maxmind.geoip2.JsonSerializable;
@@ -91,7 +90,6 @@ public record EnterpriseResponse(
9190
/**
9291
* Compact canonical constructor that sets defaults for null values.
9392
*/
94-
@MaxMindDbConstructor
9593
public EnterpriseResponse {
9694
city = city != null ? city : new City();
9795
continent = continent != null ? continent : new Continent();

src/main/java/com/maxmind/geoip2/model/IpRiskResponse.java

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
66
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
77
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
8-
import com.maxmind.db.MaxMindDbConstructor;
98
import com.maxmind.db.MaxMindDbParameter;
109
import com.maxmind.db.Network;
1110
import com.maxmind.geoip2.JsonSerializable;
@@ -35,27 +34,27 @@ public record IpRiskResponse(
3534
String ipAddress,
3635

3736
@JsonProperty("is_anonymous")
38-
@MaxMindDbParameter(name = "is_anonymous")
37+
@MaxMindDbParameter(name = "is_anonymous", useDefault = true)
3938
boolean isAnonymous,
4039

4140
@JsonProperty("is_anonymous_vpn")
42-
@MaxMindDbParameter(name = "is_anonymous_vpn")
41+
@MaxMindDbParameter(name = "is_anonymous_vpn", useDefault = true)
4342
boolean isAnonymousVpn,
4443

4544
@JsonProperty("is_hosting_provider")
46-
@MaxMindDbParameter(name = "is_hosting_provider")
45+
@MaxMindDbParameter(name = "is_hosting_provider", useDefault = true)
4746
boolean isHostingProvider,
4847

4948
@JsonProperty("is_public_proxy")
50-
@MaxMindDbParameter(name = "is_public_proxy")
49+
@MaxMindDbParameter(name = "is_public_proxy", useDefault = true)
5150
boolean isPublicProxy,
5251

5352
@JsonProperty("is_residential_proxy")
54-
@MaxMindDbParameter(name = "is_residential_proxy")
53+
@MaxMindDbParameter(name = "is_residential_proxy", useDefault = true)
5554
boolean isResidentialProxy,
5655

5756
@JsonProperty("is_tor_exit_node")
58-
@MaxMindDbParameter(name = "is_tor_exit_node")
57+
@MaxMindDbParameter(name = "is_tor_exit_node", useDefault = true)
5958
boolean isTorExitNode,
6059

6160
@JsonProperty("network")
@@ -68,44 +67,6 @@ public record IpRiskResponse(
6867
double ipRisk
6968
) implements JsonSerializable {
7069

71-
/**
72-
* Constructs an instance of {@code IpRiskResponse} with nullable boolean fields.
73-
*
74-
* @param ipAddress the IP address being checked
75-
* @param isAnonymous whether the IP address belongs to any sort of anonymous network
76-
* @param isAnonymousVpn whether the IP address belongs to an anonymous VPN system
77-
* @param isHostingProvider whether the IP address belongs to a hosting provider
78-
* @param isPublicProxy whether the IP address belongs to a public proxy system
79-
* @param isResidentialProxy whether the IP address belongs to a residential proxy system
80-
* @param isTorExitNode whether the IP address is a Tor exit node
81-
* @param network the network associated with the record
82-
* @param ipRisk the IP risk of a model
83-
*/
84-
@MaxMindDbConstructor
85-
public IpRiskResponse(
86-
@MaxMindDbParameter(name = "ip_address") String ipAddress,
87-
@MaxMindDbParameter(name = "is_anonymous") Boolean isAnonymous,
88-
@MaxMindDbParameter(name = "is_anonymous_vpn") Boolean isAnonymousVpn,
89-
@MaxMindDbParameter(name = "is_hosting_provider") Boolean isHostingProvider,
90-
@MaxMindDbParameter(name = "is_public_proxy") Boolean isPublicProxy,
91-
@MaxMindDbParameter(name = "is_residential_proxy") Boolean isResidentialProxy,
92-
@MaxMindDbParameter(name = "is_tor_exit_node") Boolean isTorExitNode,
93-
@MaxMindDbParameter(name = "network") Network network,
94-
@MaxMindDbParameter(name = "ip_risk") double ipRisk
95-
) {
96-
this(
97-
ipAddress,
98-
isAnonymous != null ? isAnonymous : false,
99-
isAnonymousVpn != null ? isAnonymousVpn : false,
100-
isHostingProvider != null ? isHostingProvider : false,
101-
isPublicProxy != null ? isPublicProxy : false,
102-
isResidentialProxy != null ? isResidentialProxy : false,
103-
isTorExitNode != null ? isTorExitNode : false,
104-
network,
105-
ipRisk
106-
);
107-
}
108-
10970
/**
11071
* Constructs an instance of {@code IpRiskResponse}.
11172
*

src/main/java/com/maxmind/geoip2/model/IspResponse.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
66
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
77
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
8-
import com.maxmind.db.MaxMindDbConstructor;
98
import com.maxmind.db.MaxMindDbParameter;
109
import com.maxmind.db.Network;
1110
import com.maxmind.geoip2.JsonSerializable;
@@ -66,13 +65,6 @@ public record IspResponse(
6665
Network network
6766
) implements JsonSerializable {
6867

69-
/**
70-
* Canonical constructor.
71-
*/
72-
@MaxMindDbConstructor
73-
public IspResponse {
74-
}
75-
7668
/**
7769
* Constructs an instance of {@code IspResponse}.
7870
*

src/main/java/com/maxmind/geoip2/record/City.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.fasterxml.jackson.annotation.JacksonInject;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5-
import com.maxmind.db.MaxMindDbConstructor;
65
import com.maxmind.db.MaxMindDbParameter;
76
import com.maxmind.geoip2.NamedRecord;
87
import java.util.ArrayList;
@@ -47,7 +46,6 @@ public record City(
4746
/**
4847
* Compact canonical constructor that ensures immutability and handles null values.
4948
*/
50-
@MaxMindDbConstructor
5149
public City {
5250
locales = locales != null ? List.copyOf(locales) : List.of();
5351
names = names != null ? Map.copyOf(names) : Map.of();

0 commit comments

Comments
 (0)