Skip to content

Allow serialization of InetAddress as simple numeric host address #1605

@2is10

Description

@2is10

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions