Add support for more java.net.* classes
See original GitHub issueI’d primarily be interested in support java.net.InetAddress
and java.net.InetSocketAddress
.
Field type | Factory |
---|---|
InetAddress |
InetAddress::getByName |
InetAddress[] |
InetAddress::getAllByName |
InetSocketAddress |
InetSocketAddress::new (may need to split on last : of string, or accept a map of hostname and port for construction) |
Just for completion’s sake, it may be nice to also support NetworkInterface
as that can convert via a string (NetworkInterface::getByName
) or an int (NetworkInterface::getByIndex
), though I’m not sure how useful it would be in comparison.
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Package java.net - Oracle Help Center
Package java.net ; InetAddress. This class represents an Internet Protocol (IP) address. ; InetSocketAddress. This class implements an IP Socket Address (IP ...
Read more >Examples on Various Classes of java.net Package - eduCBA
Java.net is a package that provides a set of classes as well as interfaces for networking in Java. Some of the classes are...
Read more >java.net.Socket Class in Java - GeeksforGeeks
The java.net.Socket class allows us to create socket objects that help us in implementing all fundamental socket operations.
Read more >java.net - Android Developers
About IPv6. Sockets; Interfaces; High level API; Protocol Handlers; Additional Specification; Interfaces; Classes; Enums; Exceptions. Added in API level 1 ...
Read more >Commons VFS and Java.net.URL - Adding support for “ram ...
public class RamHandler extends URLStreamHandler { @Override protected URLConnection openConnection(final URL u) throws IOException { //May instead use VFS ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There are some ways around this:
the standard library’s
InetAddress.getByName()
is pure if you pass in an IP address. It only does a DNS lookup if you pass in a hostname.As an alternative, there are third-party libraries that only support IP addresses, and will never do a DNS lookup. For example, Guava’s InetAddresses can parse strings like “1.2.3.4” into a
java.net.InetAddress
- https://google.github.io/guava/releases/20.0/api/docs/com/google/common/net/InetAddresses.html Unfortunately Guava is a very heavyweight library, and I’m not sure it’s worth adding a pureconfig module for it if we’re only going to use a few types.If you just want to verify that a string has a vaild hostname, you can use Guava’a
InternetDomainName
- https://google.github.io/guava/releases/20.0/api/docs/com/google/common/net/InternetDomainName.html. That class has a pure function that just verifies that a string is structurally valid, but doesn’t query DNS to see if it’s nameserved. So, “foo.bar.org” is valid, but “foo!@#.-1.__org” is invalid.If you want to verify that an Int is a valid port number you can use refined. It has types for port numbers, system port numbers, user port numbers, etc - https://github.com/fthomas/refined/blob/master/modules/core/shared/src/main/scala/eu/timepit/refined/types/net.scala
I definitely think it’s useful to have pureconfig support for
InetAddress
. I’m fine using the standard library’sInetAddress
helper functions as they’re pure as long as you give the right input.Would InetSocketAddress.createUnresolved be an option for this?