Skip to content

Commit 385f239

Browse files
oschwaldclaude
andcommitted
Update code examples to use modern record accessor methods
Replace deprecated getXXX() style methods with the modern Java record accessor methods throughout all code examples. The deprecated methods are scheduled for removal in version 6.0.0. Changes include: - response.getCountry() -> response.country() - country.getIsoCode() -> country.isoCode() - country.getName() -> country.name() - response.getMostSpecificSubdivision() -> response.mostSpecificSubdivision() - location.getLatitude() -> location.latitude() - And similar changes throughout all examples Also fixed incorrect return type in Anonymous Plus example (AnonymousIpResponse -> AnonymousPlusResponse). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5a10f5d commit 385f239

1 file changed

Lines changed: 98 additions & 98 deletions

File tree

README.md

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ InetAddress ipAddress = InetAddress.getByName("128.101.101.101");
9797
// Do the lookup
9898
CountryResponse response = client.country(ipAddress);
9999

100-
Country country = response.getCountry();
101-
System.out.println(country.getIsoCode()); // 'US'
102-
System.out.println(country.getName()); // 'United States'
103-
System.out.println(country.getNames().get("zh-CN")); // '美国'
100+
Country country = response.country();
101+
System.out.println(country.isoCode()); // 'US'
102+
System.out.println(country.name()); // 'United States'
103+
System.out.println(country.names().get("zh-CN")); // '美国'
104104
```
105105

106106
### City Plus Service ###
@@ -126,24 +126,24 @@ InetAddress ipAddress = InetAddress.getByName("128.101.101.101");
126126
// Do the lookup
127127
CityResponse response = client.city(ipAddress);
128128

129-
Country country = response.getCountry();
130-
System.out.println(country.getIsoCode()); // 'US'
131-
System.out.println(country.getName()); // 'United States'
132-
System.out.println(country.getNames().get("zh-CN")); // '美国'
129+
Country country = response.country();
130+
System.out.println(country.isoCode()); // 'US'
131+
System.out.println(country.name()); // 'United States'
132+
System.out.println(country.names().get("zh-CN")); // '美国'
133133

134-
Subdivision subdivision = response.getMostSpecificSubdivision();
135-
System.out.println(subdivision.getName()); // 'Minnesota'
136-
System.out.println(subdivision.getIsoCode()); // 'MN'
134+
Subdivision subdivision = response.mostSpecificSubdivision();
135+
System.out.println(subdivision.name()); // 'Minnesota'
136+
System.out.println(subdivision.isoCode()); // 'MN'
137137

138-
City city = response.getCity();
139-
System.out.println(city.getName()); // 'Minneapolis'
138+
City city = response.city();
139+
System.out.println(city.name()); // 'Minneapolis'
140140

141-
Postal postal = response.getPostal();
142-
System.out.println(postal.getCode()); // '55455'
141+
Postal postal = response.postal();
142+
System.out.println(postal.code()); // '55455'
143143

144-
Location location = response.getLocation();
145-
System.out.println(location.getLatitude()); // 44.9733
146-
System.out.println(location.getLongitude()); // -93.2323
144+
Location location = response.location();
145+
System.out.println(location.latitude()); // 44.9733
146+
System.out.println(location.longitude()); // -93.2323
147147
```
148148

149149
### Insights Service ###
@@ -167,32 +167,32 @@ InetAddress ipAddress = InetAddress.getByName("128.101.101.101");
167167
// Do the lookup
168168
InsightsResponse response = client.insights(ipAddress);
169169

170-
Country country = response.getCountry();
171-
System.out.println(country.getIsoCode()); // 'US'
172-
System.out.println(country.getName()); // 'United States'
173-
System.out.println(country.getNames().get("zh-CN")); // '美国'
174-
System.out.println(country.getConfidence()); // 99
170+
Country country = response.country();
171+
System.out.println(country.isoCode()); // 'US'
172+
System.out.println(country.name()); // 'United States'
173+
System.out.println(country.names().get("zh-CN")); // '美国'
174+
System.out.println(country.confidence()); // 99
175175

176-
Subdivision subdivision = response.getMostSpecificSubdivision();
177-
System.out.println(subdivision.getName()); // 'Minnesota'
178-
System.out.println(subdivision.getIsoCode()); // 'MN'
179-
System.out.println(subdivision.getConfidence()); // 90
176+
Subdivision subdivision = response.mostSpecificSubdivision();
177+
System.out.println(subdivision.name()); // 'Minnesota'
178+
System.out.println(subdivision.isoCode()); // 'MN'
179+
System.out.println(subdivision.confidence()); // 90
180180

181-
City city = response.getCity();
182-
System.out.println(city.getName()); // 'Minneapolis'
183-
System.out.println(city.getConfidence()); // 50
181+
City city = response.city();
182+
System.out.println(city.name()); // 'Minneapolis'
183+
System.out.println(city.confidence()); // 50
184184

185-
Postal postal = response.getPostal();
186-
System.out.println(postal.getCode()); // '55455'
187-
System.out.println(postal.getConfidence()); // 40
185+
Postal postal = response.postal();
186+
System.out.println(postal.code()); // '55455'
187+
System.out.println(postal.confidence()); // 40
188188

189-
Location location = response.getLocation();
190-
System.out.println(location.getLatitude()); // 44.9733
191-
System.out.println(location.getLongitude()); // -93.2323
192-
System.out.println(location.getAccuracyRadius()); // 3
193-
System.out.println(location.getTimeZone()); // 'America/Chicago'
189+
Location location = response.location();
190+
System.out.println(location.latitude()); // 44.9733
191+
System.out.println(location.longitude()); // -93.2323
192+
System.out.println(location.accuracyRadius()); // 3
193+
System.out.println(location.timeZone()); // 'America/Chicago'
194194

195-
System.out.println(response.getTraits().getUserType()); // 'college'
195+
System.out.println(response.traits().userType()); // 'college'
196196
```
197197

198198
## Database Usage ##
@@ -264,24 +264,24 @@ InetAddress ipAddress = InetAddress.getByName("128.101.101.101");
264264
// "country".
265265
CityResponse response = reader.city(ipAddress);
266266

267-
Country country = response.getCountry();
268-
System.out.println(country.getIsoCode()); // 'US'
269-
System.out.println(country.getName()); // 'United States'
270-
System.out.println(country.getNames().get("zh-CN")); // '美国'
267+
Country country = response.country();
268+
System.out.println(country.isoCode()); // 'US'
269+
System.out.println(country.name()); // 'United States'
270+
System.out.println(country.names().get("zh-CN")); // '美国'
271271

272-
Subdivision subdivision = response.getMostSpecificSubdivision();
273-
System.out.println(subdivision.getName()); // 'Minnesota'
274-
System.out.println(subdivision.getIsoCode()); // 'MN'
272+
Subdivision subdivision = response.mostSpecificSubdivision();
273+
System.out.println(subdivision.name()); // 'Minnesota'
274+
System.out.println(subdivision.isoCode()); // 'MN'
275275

276-
City city = response.getCity();
277-
System.out.println(city.getName()); // 'Minneapolis'
276+
City city = response.city();
277+
System.out.println(city.name()); // 'Minneapolis'
278278

279-
Postal postal = response.getPostal();
280-
System.out.println(postal.getCode()); // '55455'
279+
Postal postal = response.postal();
280+
System.out.println(postal.code()); // '55455'
281281

282-
Location location = response.getLocation();
283-
System.out.println(location.getLatitude()); // 44.9733
284-
System.out.println(location.getLongitude()); // -93.2323
282+
Location location = response.location();
283+
System.out.println(location.latitude()); // 44.9733
284+
System.out.println(location.longitude()); // -93.2323
285285
```
286286

287287
### Anonymous IP ###
@@ -302,7 +302,7 @@ try (DatabaseReader reader = new DatabaseReader.Builder(database).build()) {
302302
System.out.println(response.isHostingProvider()); // false
303303
System.out.println(response.isPublicProxy()); // false
304304
System.out.println(response.isResidentialProxy()); // false
305-
System.out.println(response.isTorExitNode()); //true
305+
System.out.println(response.isTorExitNode()); // true
306306
}
307307
```
308308

@@ -317,17 +317,17 @@ File database = new File("/path/to/GeoIP-Anonymous-Plus.mmdb");
317317
try (DatabaseReader reader = new DatabaseReader.Builder(database).build()) {
318318
InetAddress ipAddress = InetAddress.getByName("85.25.43.84");
319319

320-
AnonymousIpResponse response = reader.anonymousPlus(ipAddress);
320+
AnonymousPlusResponse response = reader.anonymousPlus(ipAddress);
321321

322-
System.out.println(response.getAnonymizerConfidence()); // 30
322+
System.out.println(response.anonymizerConfidence()); // 30
323323
System.out.println(response.isAnonymous()); // true
324324
System.out.println(response.isAnonymousVpn()); // false
325325
System.out.println(response.isHostingProvider()); // false
326326
System.out.println(response.isPublicProxy()); // false
327327
System.out.println(response.isResidentialProxy()); // false
328328
System.out.println(response.isTorExitNode()); // true
329-
System.out.println(response.getNetworkLastSeen()); // "2025-04-14"
330-
System.out.println(response.getProviderName()); // "FooBar VPN"
329+
System.out.println(response.networkLastSeen()); // "2025-04-14"
330+
System.out.println(response.providerName()); // "FooBar VPN"
331331
}
332332
```
333333

@@ -345,8 +345,8 @@ try (DatabaseReader reader = new DatabaseReader.Builder(database).build()) {
345345

346346
AsnResponse response = reader.asn(ipAddress);
347347

348-
System.out.println(response.getAutonomousSystemNumber()); // 217
349-
System.out.println(response.getAutonomousSystemOrganization()); // 'University of Minnesota'
348+
System.out.println(response.autonomousSystemNumber()); // 217
349+
System.out.println(response.autonomousSystemOrganization()); // 'University of Minnesota'
350350
}
351351
```
352352

@@ -364,8 +364,8 @@ InetAddress ipAddress = InetAddress.getByName("128.101.101.101");
364364

365365
ConnectionTypeResponse response = reader.connectionType(ipAddress);
366366

367-
// getConnectionType() returns a ConnectionType enum
368-
ConnectionType type = response.getConnectionType();
367+
// connectionType() returns a ConnectionType enum
368+
ConnectionType type = response.connectionType();
369369

370370
System.out.println(type); // 'Corporate'
371371
```
@@ -384,7 +384,7 @@ InetAddress ipAddress = InetAddress.getByName("128.101.101.101");
384384

385385
DomainResponse response = reader.domain(ipAddress);
386386

387-
System.out.println(response.getDomain()); // 'umn.edu'
387+
System.out.println(response.domain()); // 'umn.edu'
388388
```
389389

390390
### Enterprise ###
@@ -401,29 +401,29 @@ try (DatabaseReader reader = new DatabaseReader.Builder(database).build()) {
401401
// Use the enterprise(ip) method to do a lookup in the Enterprise database
402402
EnterpriseResponse response = reader.enterprise(ipAddress);
403403

404-
Country country = response.getCountry();
405-
System.out.println(country.getIsoCode()); // 'US'
406-
System.out.println(country.getName()); // 'United States'
407-
System.out.println(country.getNames().get("zh-CN")); // '美国'
408-
System.out.println(country.getConfidence()); // 99
409-
410-
Subdivision subdivision = response.getMostSpecificSubdivision();
411-
System.out.println(subdivision.getName()); // 'Minnesota'
412-
System.out.println(subdivision.getIsoCode()); // 'MN'
413-
System.out.println(subdivision.getConfidence()); // 77
414-
415-
City city = response.getCity();
416-
System.out.println(city.getName()); // 'Minneapolis'
417-
System.out.println(city.getConfidence()); // 11
418-
419-
Postal postal = response.getPostal();
420-
System.out.println(postal.getCode()); // '55455'
421-
System.out.println(postal.getConfidence()); // 5
422-
423-
Location location = response.getLocation();
424-
System.out.println(location.getLatitude()); // 44.9733
425-
System.out.println(location.getLongitude()); // -93.2323
426-
System.out.println(location.getAccuracyRadius()); // 50
404+
Country country = response.country();
405+
System.out.println(country.isoCode()); // 'US'
406+
System.out.println(country.name()); // 'United States'
407+
System.out.println(country.names().get("zh-CN")); // '美国'
408+
System.out.println(country.confidence()); // 99
409+
410+
Subdivision subdivision = response.mostSpecificSubdivision();
411+
System.out.println(subdivision.name()); // 'Minnesota'
412+
System.out.println(subdivision.isoCode()); // 'MN'
413+
System.out.println(subdivision.confidence()); // 77
414+
415+
City city = response.city();
416+
System.out.println(city.name()); // 'Minneapolis'
417+
System.out.println(city.confidence()); // 11
418+
419+
Postal postal = response.postal();
420+
System.out.println(postal.code()); // '55455'
421+
System.out.println(postal.confidence()); // 5
422+
423+
Location location = response.location();
424+
System.out.println(location.latitude()); // 44.9733
425+
System.out.println(location.longitude()); // -93.2323
426+
System.out.println(location.accuracyRadius()); // 50
427427
}
428428
```
429429

@@ -441,10 +441,10 @@ InetAddress ipAddress = InetAddress.getByName("128.101.101.101");
441441

442442
IspResponse response = reader.isp(ipAddress);
443443

444-
System.out.println(response.getAutonomousSystemNumber()); // 217
445-
System.out.println(response.getAutonomousSystemOrganization()); // 'University of Minnesota'
446-
System.out.println(response.getIsp()); // 'University of Minnesota'
447-
System.out.println(response.getOrganization()); // 'University of Minnesota'
444+
System.out.println(response.autonomousSystemNumber()); // 217
445+
System.out.println(response.autonomousSystemOrganization()); // 'University of Minnesota'
446+
System.out.println(response.isp()); // 'University of Minnesota'
447+
System.out.println(response.organization()); // 'University of Minnesota'
448448
```
449449

450450
## Exceptions ##
@@ -469,17 +469,17 @@ the above exceptions.
469469

470470
## Values to use for Database or Map Keys ##
471471

472-
**We strongly discourage you from using a value from any `getNames` method as
472+
**We strongly discourage you from using a value from any `names()` method as
473473
a key in a database or map.**
474474

475475
These names may change between releases. Instead we recommend using one of the
476476
following:
477477

478-
* `com.maxmind.geoip2.record.City` - `City.getGeoNameId`
479-
* `com.maxmind.geoip2.record.Continent` - `Continent.getCode` or `Continent.getGeoNameId`
480-
* `com.maxmind.geoip2.record.Country` and `com.maxmind.geoip2.record.RepresentedCountry` - `Country.getIsoCode`
481-
or `Country.getGeoNameId`
482-
* `com.maxmind.geoip2.record.Subdivision` - `Subdivision.getIsoCode` or `Subdivision.getGeoNameId`
478+
* `com.maxmind.geoip2.record.City` - `City.geonameId`
479+
* `com.maxmind.geoip2.record.Continent` - `Continent.code` or `Continent.geonameId`
480+
* `com.maxmind.geoip2.record.Country` and `com.maxmind.geoip2.record.RepresentedCountry` - `Country.isoCode`
481+
or `Country.geonameId`
482+
* `com.maxmind.geoip2.record.Subdivision` - `Subdivision.isoCode` or `Subdivision.geonameId`
483483

484484
## Multi-Threaded Use ##
485485

@@ -501,7 +501,7 @@ documentation](https://dev.maxmind.com/geoip/docs/web-services?lang=en) for
501501
details on what data each web service may return.
502502

503503
The only piece of data which is always returned is the `ip_address`
504-
available at `lookup.getTraits().getIpAddress()`.
504+
available at `lookup.traits().ipAddress()`.
505505

506506
## Integration with GeoNames ##
507507

@@ -511,7 +511,7 @@ populated places. They offer both free and paid premium data. Each
511511
feature is uniquely identified by a `geonameId`, which is an integer.
512512

513513
Many of the records returned by the GeoIP2 web services and databases
514-
include a `getGeoNameId()` method. This is the ID of a geographical
514+
include a `geonameId()` method. This is the ID of a geographical
515515
feature (city, region, country, etc.) in the GeoNames database.
516516

517517
Some of the data that MaxMind provides is also sourced from GeoNames. We

0 commit comments

Comments
 (0)