-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
An InetAddress
is defined this way in its Javadoc:
This class represents an Internet Protocol (IP) address.
An instance ... consists of an IP address and possibly its corresponding host name.
The IP address is central. The hostname is optional, peripheral.
However, Jackson’s InetAddressSerializer just uses the hostname, if present, and discards the IP address. This is critical information loss. A hostname isn’t guaranteed to be resolvable to the same IP address (or at all) where/when deserialized.
A corresponding issue with the deserializer is that hostname resolution (network access) is attempted for any input string that isn’t a valid IP address. This violates the Principle of Least Astonishment.
These seem like important issues to fix, but I’m not sure how to do it in a backwards-compatible way. The JDK’s InetAddress
is partly to blame, the minefield that it is.
I suggest taking inspiration from Guava’s InetAddresses and doing some of your own parsing.
You’ll need to decide whether to serialize to just the IP address or to try to also preserve the hostname, if present. For what it’s worth, my team’s present use cases only care about the IP address. However, any information loss could be surprising to people who use this library.