29
29
import java .util .List ;
30
30
import java .util .Map ;
31
31
import java .util .Optional ;
32
+ import java .util .Properties ;
32
33
import java .util .UUID ;
33
34
34
35
import io .avaje .json .JsonAdapter ;
37
38
import io .avaje .json .JsonWriter ;
38
39
import io .avaje .jsonb .AdapterFactory ;
39
40
import io .avaje .jsonb .Jsonb ;
41
+ import io .avaje .jsonb .Types ;
40
42
41
43
final class BasicTypeAdapters {
42
44
@@ -49,14 +51,15 @@ final class BasicTypeAdapters {
49
51
if (type == Byte .class ) return new ByteAdapter ().nullSafe ();
50
52
if (type == Character .class ) return new CharacterAdapter ().nullSafe ();
51
53
if (type == Short .class ) return new ShortAdapter ().nullSafe ();
54
+ if (type == Object .class ) return new ObjectJsonAdapter (jsonb ).nullSafe ();
52
55
if (type == UUID .class ) return new UuidAdapter ().nullSafe ();
53
56
if (type == URL .class ) return new UrlAdapter ().nullSafe ();
54
57
if (type == URI .class ) return new UriAdapter ().nullSafe ();
55
- if (type == InetAddress .class ) return new InetAddressAdapter ().nullSafe ();
56
- if (type == Inet4Address .class ) return new InetAddressAdapter ().nullSafe ();
57
- if (type == Inet6Address .class ) return new InetAddressAdapter ().nullSafe ();
58
+ if (type == Properties .class ) return new PropertiesAdapter (jsonb ).nullSafe ();
59
+ if (type == InetAddress .class || type == Inet4Address .class || type == Inet6Address .class ) {
60
+ return new InetAddressAdapter ().nullSafe ();
61
+ }
58
62
if (type == StackTraceElement .class ) return new StackTraceElementAdapter ().nullSafe ();
59
- if (type == Object .class ) return new ObjectJsonAdapter (jsonb ).nullSafe ();
60
63
if (type == Throwable .class ) return new ThrowableAdapter (jsonb ).nullSafe ();
61
64
62
65
final Class <?> rawType = Util .rawType (type );
@@ -121,6 +124,35 @@ public String toString() {
121
124
}
122
125
}
123
126
127
+ private static final class PropertiesAdapter implements JsonAdapter <Properties > {
128
+ private JsonAdapter <Map <Object , Object >> mapAdapter ;
129
+
130
+ private PropertiesAdapter (Jsonb jsonb ) {
131
+ this .mapAdapter = jsonb .adapter (Types .mapOf (Object .class ));
132
+ }
133
+
134
+ @ Override
135
+ public Properties fromJson (JsonReader reader ) {
136
+ var map = mapAdapter .fromJson (reader );
137
+ if (map == null ) {
138
+ return null ;
139
+ }
140
+ var properties = new Properties ();
141
+ properties .putAll (map );
142
+ return properties ;
143
+ }
144
+
145
+ @ Override
146
+ public void toJson (JsonWriter writer , Properties value ) {
147
+ mapAdapter .toJson (writer , value );
148
+ }
149
+
150
+ @ Override
151
+ public String toString () {
152
+ return "JsonAdapter(Properties)" ;
153
+ }
154
+ }
155
+
124
156
private static final class InetAddressAdapter implements JsonAdapter <InetAddress > {
125
157
@ Override
126
158
public InetAddress fromJson (JsonReader reader ) {
0 commit comments