Skip to content

Commit 9e6f7f1

Browse files
committed
Add InetAddress test to blackbox-test
Signed-off-by: Mechite <contact@mechite.com>
1 parent 58ab3d1 commit 9e6f7f1

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.example.customer.inetaddress;
2+
3+
import io.avaje.jsonb.Json;
4+
5+
import java.net.Inet4Address;
6+
import java.net.Inet6Address;
7+
import java.net.InetAddress;
8+
9+
@Json
10+
public record MyInetAddress(
11+
Inet4Address ipv4,
12+
Inet6Address ipv6,
13+
InetAddress ipv4Generic,
14+
InetAddress ipv6Generic
15+
) {
16+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.example.customer.inetaddress;
2+
3+
import io.avaje.jsonb.JsonType;
4+
import io.avaje.jsonb.Jsonb;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.io.IOException;
8+
import java.net.Inet4Address;
9+
import java.net.Inet6Address;
10+
import java.net.InetAddress;
11+
12+
import static org.assertj.core.api.Assertions.assertThat;
13+
14+
class MyInetAddressTest {
15+
16+
Jsonb jsonb = Jsonb.builder().build();
17+
JsonType<MyInetAddress> jsonType = jsonb.type(MyInetAddress.class);
18+
19+
@Test
20+
void toJson_fromJson() throws IOException {
21+
22+
MyInetAddress myInetAddress = new MyInetAddress(
23+
(Inet4Address) InetAddress.getByName("165.124.194.133"),
24+
(Inet6Address) InetAddress.getByName("1985:5b4d:9a9e:babc:5a1d:b44e:9942:07b0"),
25+
InetAddress.getByName("165.124.194.133"),
26+
InetAddress.getByName("1985:5b4d:9a9e:babc:5a1d:b44e:9942:07b0")
27+
);
28+
29+
String asJson = jsonType.toJson(myInetAddress);
30+
MyInetAddress fromJson = jsonType.fromJson(asJson);
31+
32+
assertThat(fromJson).isEqualTo(myInetAddress);
33+
}
34+
}

jsonb/src/main/java/io/avaje/jsonb/core/BasicTypeAdapters.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ final class BasicTypeAdapters {
4949
if (type == URL.class) return new UrlAdapter().nullSafe();
5050
if (type == URI.class) return new UriAdapter().nullSafe();
5151
if (type == InetAddress.class) return new InetAddressAdapter().nullSafe();
52+
if (type == Inet4Address.class) return new InetAddressAdapter().nullSafe();
53+
if (type == Inet6Address.class) return new InetAddressAdapter().nullSafe();
5254
if (type == StackTraceElement.class) return new StackTraceElementAdapter().nullSafe();
5355
if (type == Object.class) return new ObjectJsonAdapter(jsonb).nullSafe();
5456
if (type == Throwable.class) return new ThrowableAdapter(jsonb).nullSafe();

0 commit comments

Comments
 (0)