File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
main/java/org/example/customer/inetaddress
test/java/org/example/customer/inetaddress
jsonb/src/main/java/io/avaje/jsonb/core Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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 ();
You can’t perform that action at this time.
0 commit comments