-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from Mechite/main
Add InetAddressAdapter for serialization of all InetAddress variations
- Loading branch information
Showing
3 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
blackbox-test/src/main/java/org/example/customer/inetaddress/MyInetAddress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.example.customer.inetaddress; | ||
|
||
import io.avaje.jsonb.Json; | ||
|
||
import java.net.Inet4Address; | ||
import java.net.Inet6Address; | ||
import java.net.InetAddress; | ||
|
||
@Json | ||
public record MyInetAddress( | ||
Inet4Address ipv4, | ||
Inet6Address ipv6, | ||
InetAddress ipv4Generic, | ||
InetAddress ipv6Generic | ||
) { | ||
} |
34 changes: 34 additions & 0 deletions
34
blackbox-test/src/test/java/org/example/customer/inetaddress/MyInetAddressTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.example.customer.inetaddress; | ||
|
||
import io.avaje.jsonb.JsonType; | ||
import io.avaje.jsonb.Jsonb; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.net.Inet4Address; | ||
import java.net.Inet6Address; | ||
import java.net.InetAddress; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class MyInetAddressTest { | ||
|
||
Jsonb jsonb = Jsonb.builder().build(); | ||
JsonType<MyInetAddress> jsonType = jsonb.type(MyInetAddress.class); | ||
|
||
@Test | ||
void toJson_fromJson() throws IOException { | ||
|
||
MyInetAddress myInetAddress = new MyInetAddress( | ||
(Inet4Address) InetAddress.getByName("165.124.194.133"), | ||
(Inet6Address) InetAddress.getByName("1985:5b4d:9a9e:babc:5a1d:b44e:9942:07b0"), | ||
InetAddress.getByName("165.124.194.133"), | ||
InetAddress.getByName("1985:5b4d:9a9e:babc:5a1d:b44e:9942:07b0") | ||
); | ||
|
||
String asJson = jsonType.toJson(myInetAddress); | ||
MyInetAddress fromJson = jsonType.fromJson(asJson); | ||
|
||
assertThat(fromJson).isEqualTo(myInetAddress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters