Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/main/java/com/maxmind/geoip2/DatabaseReader.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.maxmind.geoip2;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.maxmind.db.InvalidDatabaseException;
import com.maxmind.db.Metadata;
Expand Down Expand Up @@ -43,6 +40,7 @@ private DatabaseReader(Builder builder) throws IOException {
"Unsupported Builder configuration: expected either File or URL");
}
this.om = new ObjectMapper();
this.om.configure(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also update the ObjectMapper in WebServiceClient with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

this.om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
false);
this.om.configure(
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/maxmind/geoip2/WebServiceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpHeaders;
Expand Down Expand Up @@ -266,6 +267,7 @@ private <T> T responseFor(String path, InetAddress ipAddress, Class<T> cls)
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
false);
mapper.configure(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS, false);

try {
return mapper.reader(cls).with(inject).readValue(body);
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/com/maxmind/geoip2/model/AbstractCityResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.maxmind.geoip2.record.City;
import com.maxmind.geoip2.record.Location;
import com.maxmind.geoip2.record.Postal;
import com.maxmind.geoip2.record.Subdivision;
import com.maxmind.geoip2.record.*;

abstract class AbstractCityResponse extends AbstractCountryResponse {
@JsonProperty
private final City city = new City();
@JsonProperty
private final Location location = new Location();
@JsonProperty
private final Postal postal = new Postal();

@JsonProperty("subdivisions")
private final ArrayList<Subdivision> subdivisions = new ArrayList<Subdivision>();
private final City city;
private final Location location;
private final Postal postal;
private final List<Subdivision> subdivisions;

AbstractCityResponse(MaxMind maxmind, Country registeredCountry, Traits traits, Country country, Continent continent,
Location location, List<Subdivision> subdivisions, RepresentedCountry representedCountry, Postal postal, City city) {
super(continent, country, registeredCountry, maxmind, representedCountry, traits);
this.city = city != null ? city : new City();
this.location = location != null ? location : new Location();
this.postal = postal != null ? postal : new Postal();
this.subdivisions = subdivisions != null ? subdivisions : new ArrayList<Subdivision>();
}

/**
* @return City record for the requested IP address.
*/
public com.maxmind.geoip2.record.City getCity() {
public City getCity() {
return this.city;
}

Expand Down
59 changes: 30 additions & 29 deletions src/main/java/com/maxmind/geoip2/model/AbstractCountryResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,40 @@
import com.maxmind.geoip2.record.Traits;

abstract class AbstractCountryResponse extends AbstractResponse {
@JsonProperty
private final Continent continent = new Continent();

@JsonProperty
private final Country country = new Country();
private final Continent continent;
private final Country country;
private final Country registeredCountry;
private final MaxMind maxmind;
private final RepresentedCountry representedCountry;
private final Traits traits;

@JsonProperty("registered_country")
private final Country registeredCountry = new Country();
AbstractCountryResponse(Continent continent, Country country, Country registeredCountry, MaxMind maxmind, RepresentedCountry representedCountry, Traits traits) {
this.continent = continent != null ? continent : new Continent();
this.country = country != null ? country : new Country();
this.registeredCountry = registeredCountry != null ? registeredCountry : new Country();
this.maxmind = maxmind != null ? maxmind : new MaxMind();
this.representedCountry = representedCountry != null ? representedCountry : new RepresentedCountry();
this.traits = traits != null ? traits : new Traits();
}

/**
* @return MaxMind record containing data related to your account.
*/
@JsonProperty("maxmind")
private final MaxMind maxmind = new MaxMind();

@JsonProperty("represented_country")
private final RepresentedCountry representedCountry = new RepresentedCountry();
public MaxMind getMaxMind() {
return this.maxmind;
}

@JsonProperty
private final Traits traits = new Traits();
/**
* @return Registered country record for the requested IP address. This
* record represents the country where the ISP has registered a
* given IP block and may differ from the user's country.
*/
@JsonProperty("registered_country")
public Country getRegisteredCountry() {
return this.registeredCountry;
}

/**
* @return Continent record for the requested IP address.
Expand All @@ -42,29 +59,13 @@ public Country getCountry() {
return this.country;
}

/**
* @return MaxMind record containing data related to your account.
*/
@JsonProperty("maxmind")
public MaxMind getMaxMind() {
return this.maxmind;
}

/**
* @return Registered country record for the requested IP address. This
* record represents the country where the ISP has registered a
* given IP block and may differ from the user's country.
*/
public Country getRegisteredCountry() {
return this.registeredCountry;
}

/**
* @return Represented country record for the requested IP address. The
* represented country is used for things like military bases. It is
* only present when the represented country differs from the
* country.
*/
@JsonProperty("represented_country")
public RepresentedCountry getRepresentedCountry() {
return this.representedCountry;
}
Expand Down
41 changes: 23 additions & 18 deletions src/main/java/com/maxmind/geoip2/model/AnonymousIpResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,60 @@
*/
public class AnonymousIpResponse extends AbstractResponse {

@JsonProperty("is_anonymous")
private boolean isAnonymous;

@JsonProperty("is_anonymous_vpn")
private boolean isAnonymousVpn;

@JsonProperty("is_hosting_provider")
private boolean isHostingProvider;

@JsonProperty("is_public_proxy")
private boolean isPublicProxy;

@JsonProperty("is_tor_exit_node")
private boolean isTorExitNode;

@JsonProperty("ip_address")
private String ipAddress;

private final boolean isAnonymous;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this class has the same serialization issue.

private final boolean isAnonymousVpn;
private final boolean isHostingProvider;
private final boolean isPublicProxy;
private final boolean isTorExitNode;
private final String ipAddress;

public AnonymousIpResponse(@JsonProperty("is_anonymous") boolean isAnonymous, @JsonProperty("is_anonymous_vpn") boolean isAnonymousVpn,
@JsonProperty("is_hosting_provider") boolean isHostingProvider, @JsonProperty("is_public_proxy") boolean isPublicProxy,
@JsonProperty("is_tor_exit_node") boolean isTorExitNode, @JsonProperty("ip_address") String ipAddress) {
this.isAnonymous = isAnonymous;
this.isAnonymousVpn = isAnonymousVpn;
this.isHostingProvider = isHostingProvider;
this.isPublicProxy = isPublicProxy;
this.isTorExitNode = isTorExitNode;
this.ipAddress = ipAddress;
}

/**
* @return whether the IP address belongs to any sort of anonymous network.
*/
@JsonProperty("is_anonymous")
public boolean isAnonymous() {
return isAnonymous;
}

/**
* @return whether the IP address belongs to an anonymous VPN system.
*/
@JsonProperty("is_anonymous_vpn")
public boolean isAnonymousVpn() {
return isAnonymousVpn;
}

/**
* @return whether the IP address belongs to a hosting provider.
*/
@JsonProperty("is_hosting_provider")
public boolean isHostingProvider() {
return isHostingProvider;
}

/**
* @return whether the IP address belongs to a public proxy.
*/
@JsonProperty("is_public_proxy")
public boolean isPublicProxy() {
return isPublicProxy;
}

/**
* @return whether the IP address is a Tor exit node.
*/
@JsonProperty("is_tor_exit_node")
public boolean isTorExitNode() {
return isTorExitNode;
}
Expand All @@ -65,6 +69,7 @@ public boolean isTorExitNode() {
/**
* @return The IP address that the data in the model is for.
*/
@JsonProperty("ip_address")
public String getIpAddress() {
return this.ipAddress;
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/maxmind/geoip2/model/CityResponse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.maxmind.geoip2.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.maxmind.geoip2.record.*;

import java.util.ArrayList;

/**
* <p>
* This class provides a model for the data returned by the GeoIP2 Precision:
Expand All @@ -15,4 +20,13 @@
* </p>
*/
public final class CityResponse extends AbstractCityResponse {

public CityResponse(@JsonProperty("continent") Continent continent, @JsonProperty("country") Country country,
@JsonProperty("registered_country") Country registeredCountry,
@JsonProperty("maxmind") MaxMind maxmind,
@JsonProperty("represented_country") RepresentedCountry representedCountry,
@JsonProperty("traits") Traits traits, @JsonProperty("city") City city, @JsonProperty("location") Location location,
@JsonProperty("postal") Postal postal, @JsonProperty("subdivisions") ArrayList<Subdivision> subdivisions) {
super(maxmind, registeredCountry, traits, country, continent, location, subdivisions, representedCountry, postal, city);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,26 @@ public String toString() {
}
}

@JsonProperty("connection_type")
private ConnectionType connectionType;
private final ConnectionType connectionType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getter likely needs the annotation.

private final String ipAddress;

@JsonProperty("ip_address")
private String ipAddress;
public ConnectionTypeResponse(@JsonProperty("connection_type") ConnectionType connectionType, @JsonProperty("ip_address") String ipAddress) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As do all the ip_address getters.

this.connectionType = connectionType;
this.ipAddress = ipAddress;
}

/**
* @return The connection type of the IP address.
*/
@JsonProperty("connection_type")
public ConnectionType getConnectionType() {
return this.connectionType;
}

/**
* @return The IP address that the data in the model is for.
*/
@JsonProperty("ip_address")
public String getIpAddress() {
return this.ipAddress;
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/maxmind/geoip2/model/CountryResponse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.maxmind.geoip2.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.maxmind.geoip2.record.*;

/**
* This class provides a model for the data returned by the GeoIP2 Precision:
* Country end point.
Expand All @@ -8,4 +11,12 @@
* Services</a>
*/
public final class CountryResponse extends AbstractCountryResponse {

public CountryResponse(@JsonProperty("continent") Continent continent, @JsonProperty("country") Country country,
@JsonProperty("registered_country") Country registeredCountry,
@JsonProperty("maxmind") MaxMind maxmind,
@JsonProperty("represented_country") RepresentedCountry representedCountry,
@JsonProperty("traits") Traits traits) {
super(continent, country, registeredCountry, maxmind, representedCountry, traits);
}
}
11 changes: 7 additions & 4 deletions src/main/java/com/maxmind/geoip2/model/DomainResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
*/
public class DomainResponse extends AbstractResponse {

@JsonProperty
private String domain;
private final String domain;
private final String ipAddress;

@JsonProperty("ip_address")
private String ipAddress;
public DomainResponse(@JsonProperty("domain") String domain, @JsonProperty("ip_address") String ipAddress) {
this.domain = domain;
this.ipAddress = ipAddress;
}

/**
* @return the The second level domain associated with the IP address. This
Expand All @@ -25,6 +27,7 @@ public String getDomain() {
/**
* @return The IP address that the data in the model is for.
*/
@JsonProperty("ip_address")
public String getIpAddress() {
return this.ipAddress;
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/maxmind/geoip2/model/InsightsResponse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.maxmind.geoip2.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.maxmind.geoip2.record.*;

import java.util.List;

/**
* <p>
* This class provides a model for the data returned by the GeoIP2 Precision:
Expand All @@ -15,4 +20,14 @@
* </p>
*/
public class InsightsResponse extends AbstractCityResponse {

public InsightsResponse(@JsonProperty("maxmind") MaxMind maxmind, @JsonProperty("registered_country") Country registeredCountry,
@JsonProperty("traits") Traits traits, @JsonProperty("country") Country country,
@JsonProperty("continent") Continent continent, @JsonProperty("location") Location location,
@JsonProperty("subdivisions") List<Subdivision> subdivisions,
@JsonProperty("represented_country") RepresentedCountry representedCountry,
@JsonProperty("postal") Postal postal, @JsonProperty("city") City city) {
super(maxmind, registeredCountry, traits, country, continent, location, subdivisions, representedCountry, postal, city);
}

}
Loading