Skip to content

Commit 11fb16b

Browse files
authored
Merge pull request #278 from maxmind/greg/mcc-mnc
Add MCC/MNC support
2 parents e04268e + a910e6d commit 11fb16b

File tree

18 files changed

+376
-135
lines changed

18 files changed

+376
-135
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
fail-fast: false
88
matrix:
99
os: [ubuntu-latest, windows-latest, macos-latest]
10-
version: [ 8, 9, 10, 11, 12, 13, 14, 15 ]
10+
version: [ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]
1111
steps:
1212
- uses: actions/checkout@v2
1313
with:

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
CHANGELOG
22
=========
33

4+
2.16.0
5+
-------------------
6+
7+
* Support for mobile country code (MCC) and mobile network codes (MNC) was
8+
 added for the GeoIP2 ISP and Enterprise databases as well as the GeoIP2
9+
 City and Insights web services. `getMobileCountryCode()` and
10+
`getMobileNetworkCode()` were added to `com.maxmind.geoip2.model.IspResponse`
11+
 for the GeoIP2 ISP database and `com.maxmind.geoip2.record.Traits` for the
12+
Enterprise database and the GeoIP2 City and Insights web services. We expect
13+
this data to be available by late January, 2022.
14+
* Deprecated model constructors that exist for backwards compatibility.
15+
These constructors are not generally used by users of this library
16+
directly except perhaps when mocking the reader in tests.
17+
418
2.15.0 (2020-10-14)
519
-------------------
620

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,6 @@ The GeoIP2 Java API uses [Semantic Versioning](https://semver.org/).
532532

533533
## Copyright and License ##
534534

535-
This software is Copyright (c) 2013-2020 by MaxMind, Inc.
535+
This software is Copyright (c) 2013-2021 by MaxMind, Inc.
536536

537537
This is free software, licensed under the Apache License, Version 2.0.

src/main/java/com/maxmind/geoip2/WebServiceClient.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.databind.InjectableValues;
66
import com.fasterxml.jackson.databind.MapperFeature;
77
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import com.fasterxml.jackson.databind.json.JsonMapper;
89
import com.maxmind.geoip2.exception.*;
910
import com.maxmind.geoip2.model.CityResponse;
1011
import com.maxmind.geoip2.model.CountryResponse;
@@ -119,9 +120,10 @@ private WebServiceClient(Builder builder) {
119120
this.licenseKey = builder.licenseKey;
120121
this.accountId = builder.accountId;
121122

122-
mapper = new ObjectMapper();
123-
mapper.disable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS);
124-
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
123+
mapper = JsonMapper.builder()
124+
.disable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS)
125+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
126+
.build();
125127

126128
RequestConfig.Builder configBuilder = RequestConfig.custom()
127129
.setConnectTimeout(builder.connectTimeout)

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonInclude.Include;
44
import com.fasterxml.jackson.databind.MapperFeature;
55
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.fasterxml.jackson.databind.json.JsonMapper;
67

78
import java.io.IOException;
89

@@ -14,10 +15,12 @@ public abstract class AbstractResponse {
1415
* @throws IOException if there is an error serializing the object to JSON.
1516
*/
1617
public String toJson() throws IOException {
17-
ObjectMapper mapper = new ObjectMapper();
18-
mapper.setSerializationInclusion(Include.NON_NULL);
19-
mapper.setSerializationInclusion(Include.NON_EMPTY);
20-
mapper.configure(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS, false);
18+
JsonMapper mapper = JsonMapper.builder()
19+
.disable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS)
20+
.serializationInclusion(Include.NON_NULL)
21+
.serializationInclusion(Include.NON_EMPTY)
22+
.build();
23+
2124
return mapper.writeValueAsString(this);
2225
}
2326

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ public class AnonymousIpResponse extends AbstractResponse {
2828
this(null, false, false, false, false, false);
2929
}
3030

31-
// This is for compatibility and should be removed if we do a major release.
31+
/**
32+
* @deprecated This constructor exists for backwards compatibility. Will be
33+
* removed in the next major release.
34+
*/
35+
@Deprecated
3236
public AnonymousIpResponse(
3337
String ipAddress,
3438
boolean isAnonymous,
@@ -40,7 +44,11 @@ public AnonymousIpResponse(
4044
this(ipAddress, isAnonymous, isAnonymousVpn, isHostingProvider, isPublicProxy, isTorExitNode, null);
4145
}
4246

43-
// This is for compatibility and should be removed if we do a major release.
47+
/**
48+
* @deprecated This constructor exists for backwards compatibility. Will be
49+
* removed in the next major release.
50+
*/
51+
@Deprecated
4452
public AnonymousIpResponse(
4553
String ipAddress,
4654
boolean isAnonymous,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public class AsnResponse extends AbstractResponse {
2424
this((Integer) null, null, null, null);
2525
}
2626

27+
/**
28+
* @deprecated This constructor exists for backwards compatibility. Will be
29+
* removed in the next major release.
30+
*/
31+
@Deprecated
2732
public AsnResponse(
2833
Integer autonomousSystemNumber,
2934
String autonomousSystemOrganization,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public static ConnectionType fromString(String s) {
6868
this(null, null);
6969
}
7070

71+
/**
72+
* @deprecated This constructor exists for backwards compatibility. Will be
73+
* removed in the next major release.
74+
*/
75+
@Deprecated
7176
public ConnectionTypeResponse(
7277
ConnectionType connectionType,
7378
String ipAddress

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public class DomainResponse extends AbstractResponse {
2323
this(null, null);
2424
}
2525

26+
/**
27+
* @deprecated This constructor exists for backwards compatibility. Will be
28+
* removed in the next major release.
29+
*/
30+
@Deprecated
2631
public DomainResponse(
2732
String domain,
2833
String ipAddress

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ public class IspResponse extends AsnResponse {
1515

1616
private final String isp;
1717
private final String organization;
18+
private final String mobileCountryCode;
19+
private final String mobileNetworkCode;
1820

1921
IspResponse() {
2022
this(null, null, null, null, null);
2123
}
2224

25+
/**
26+
* @deprecated This constructor exists for backwards compatibility. Will be
27+
* removed in the next major release.
28+
*/
29+
@Deprecated
2330
public IspResponse(
2431
Integer autonomousSystemNumber,
2532
String autonomousSystemOrganization,
@@ -30,16 +37,52 @@ public IspResponse(
3037
this(autonomousSystemNumber, autonomousSystemOrganization, ipAddress, isp, organization, null);
3138
}
3239

40+
/**
41+
* @deprecated This constructor exists for backwards compatibility. Will be
42+
* removed in the next major release.
43+
*/
44+
@Deprecated
45+
public IspResponse(
46+
Integer autonomousSystemNumber,
47+
String autonomousSystemOrganization,
48+
String ipAddress,
49+
String isp,
50+
String organization,
51+
Network network
52+
) {
53+
this(autonomousSystemNumber, autonomousSystemOrganization, ipAddress, isp, null, null, organization, network);
54+
}
55+
56+
/**
57+
* @deprecated This constructor exists for backwards compatibility. Will be
58+
* removed in the next major release.
59+
*/
60+
@Deprecated
61+
public IspResponse(
62+
Long autonomousSystemNumber,
63+
String autonomousSystemOrganization,
64+
String ipAddress,
65+
String isp,
66+
String organization,
67+
Network network
68+
) {
69+
this(autonomousSystemNumber, autonomousSystemOrganization, ipAddress, isp, null, null, organization, network);
70+
}
71+
3372
public IspResponse(
3473
@JsonProperty("autonomous_system_number") Integer autonomousSystemNumber,
3574
@JsonProperty("autonomous_system_organization") String autonomousSystemOrganization,
3675
@JacksonInject("ip_address") @JsonProperty("ip_address") String ipAddress,
3776
@JsonProperty("isp") String isp,
77+
@JsonProperty("mobile_country_code") String mobileCountryCode,
78+
@JsonProperty("mobile_network_code") String mobileNetworkCode,
3879
@JsonProperty("organization") String organization,
3980
@JacksonInject("network") @JsonProperty("network") @JsonDeserialize(using = NetworkDeserializer.class) Network network
4081
) {
4182
super(autonomousSystemNumber, autonomousSystemOrganization, ipAddress, network);
4283
this.isp = isp;
84+
this.mobileCountryCode = mobileCountryCode;
85+
this.mobileNetworkCode = mobileNetworkCode;
4386
this.organization = organization;
4487
}
4588

@@ -49,6 +92,8 @@ public IspResponse(
4992
@MaxMindDbParameter(name="autonomous_system_organization") String autonomousSystemOrganization,
5093
@MaxMindDbParameter(name="ip_address") String ipAddress,
5194
@MaxMindDbParameter(name="isp") String isp,
95+
@MaxMindDbParameter(name="mobile_country_code") String mobileCountryCode,
96+
@MaxMindDbParameter(name="mobile_network_code") String mobileNetworkCode,
5297
@MaxMindDbParameter(name="organization") String organization,
5398
@MaxMindDbParameter(name="network") Network network
5499
) {
@@ -57,6 +102,8 @@ public IspResponse(
57102
autonomousSystemOrganization,
58103
ipAddress,
59104
isp,
105+
mobileCountryCode,
106+
mobileNetworkCode,
60107
organization,
61108
network
62109
);
@@ -72,6 +119,8 @@ public IspResponse(
72119
response.getAutonomousSystemOrganization(),
73120
ipAddress,
74121
response.getIsp(),
122+
response.getMobileCountryCode(),
123+
response.getMobileNetworkCode(),
75124
response.getOrganization(),
76125
network
77126
);
@@ -84,6 +133,26 @@ public String getIsp() {
84133
return this.isp;
85134
}
86135

136+
/**
137+
* @return The <a href="https://en.wikipedia.org/wiki/Mobile_country_code">
138+
* mobile country code (MCC)</a> associated with the IP address and ISP.
139+
* This property is available from the City and Insights web services and
140+
* the GeoIP2 Enterprise database.
141+
*/
142+
public String getMobileCountryCode() {
143+
return this.mobileCountryCode;
144+
}
145+
146+
/**
147+
* @return The <a href="https://en.wikipedia.org/wiki/Mobile_country_code">
148+
* mobile network code (MNC)</a> associated with the IP address and ISP.
149+
* This property is available from the City and Insights web services and
150+
* the GeoIP2 Enterprise database.
151+
*/
152+
public String getMobileNetworkCode() {
153+
return this.mobileNetworkCode;
154+
}
155+
87156
/**
88157
* @return The name of the organization associated with the IP address.
89158
*/

0 commit comments

Comments
 (0)