|
18 | 18 | import io.avaje.jsonb.*;
|
19 | 19 |
|
20 | 20 | import java.lang.reflect.Type;
|
21 |
| -import java.net.MalformedURLException; |
22 |
| -import java.net.URI; |
23 |
| -import java.net.URISyntaxException; |
24 |
| -import java.net.URL; |
| 21 | +import java.net.*; |
25 | 22 | import java.util.*;
|
26 | 23 |
|
27 | 24 | import static java.util.Objects.requireNonNull;
|
@@ -51,6 +48,7 @@ final class BasicTypeAdapters {
|
51 | 48 | if (type == UUID.class) return new UuidAdapter().nullSafe();
|
52 | 49 | if (type == URL.class) return new UrlAdapter().nullSafe();
|
53 | 50 | if (type == URI.class) return new UriAdapter().nullSafe();
|
| 51 | + if (type == InetAddress.class) return new InetAddressAdapter().nullSafe(); |
54 | 52 | if (type == StackTraceElement.class) return new StackTraceElementAdapter().nullSafe();
|
55 | 53 | if (type == Object.class) return new ObjectJsonAdapter(jsonb).nullSafe();
|
56 | 54 | if (type == Throwable.class) return new ThrowableAdapter(jsonb).nullSafe();
|
@@ -117,6 +115,27 @@ public String toString() {
|
117 | 115 | }
|
118 | 116 | }
|
119 | 117 |
|
| 118 | + private static final class InetAddressAdapter implements JsonAdapter<InetAddress> { |
| 119 | + @Override |
| 120 | + public InetAddress fromJson(JsonReader reader) { |
| 121 | + try { |
| 122 | + return InetAddress.getByName(reader.readString()); |
| 123 | + } catch (UnknownHostException e) { |
| 124 | + throw new JsonDataException(e); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + @Override |
| 129 | + public void toJson(JsonWriter writer, InetAddress value) { |
| 130 | + writer.value(value.getHostAddress()); |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public String toString() { |
| 135 | + return "JsonAdapter(InetAddress)"; |
| 136 | + } |
| 137 | + } |
| 138 | + |
120 | 139 | private static final class StackTraceElementAdapter implements JsonAdapter<StackTraceElement> {
|
121 | 140 | @Override
|
122 | 141 | public StackTraceElement fromJson(JsonReader reader) {
|
|
0 commit comments