|
15 | 15 | */
|
16 | 16 | package io.avaje.json.core;
|
17 | 17 |
|
| 18 | +import static java.util.Objects.requireNonNull; |
| 19 | + |
| 20 | +import java.lang.reflect.Type; |
| 21 | + |
18 | 22 | import io.avaje.json.JsonAdapter;
|
19 | 23 | import io.avaje.json.JsonDataException;
|
20 | 24 | import io.avaje.json.JsonReader;
|
21 | 25 | import io.avaje.json.JsonWriter;
|
22 | 26 |
|
23 |
| -import java.lang.reflect.Type; |
24 |
| - |
25 |
| -import static java.util.Objects.requireNonNull; |
26 |
| - |
27 | 27 | final class BaseAdapters {
|
28 | 28 |
|
| 29 | + private static final JsonAdapter<String> STRING_ADAPTER = new StringAdapter().nullSafe(); |
| 30 | + private static final LongAdapter LONG_ADAPTER = new LongAdapter(); |
| 31 | + private static final JsonAdapter<Long> NULL_SAFE_LONG = LONG_ADAPTER.nullSafe(); |
| 32 | + private static final IntegerAdapter INTEGER_ADAPTER = new IntegerAdapter(); |
| 33 | + private static final JsonAdapter<Integer> NULL_SAFE_INT = INTEGER_ADAPTER.nullSafe(); |
| 34 | + private static final FloatAdapter FLOAT_ADAPTER = new FloatAdapter(); |
| 35 | + private static final JsonAdapter<Float> NULL_SAFE_FLOAT = FLOAT_ADAPTER.nullSafe(); |
| 36 | + private static final DoubleAdapter DOUBLE_ADAPTER = new DoubleAdapter(); |
| 37 | + private static final JsonAdapter<Double> NULL_SAFE_DOUBLE = DOUBLE_ADAPTER.nullSafe(); |
| 38 | + private static final BooleanAdapter BOOLEAN_ADAPTER = new BooleanAdapter(); |
| 39 | + private static final JsonAdapter<Boolean> NULL_SAFE_BOOLEAN = BOOLEAN_ADAPTER.nullSafe(); |
| 40 | + |
29 | 41 | static JsonAdapter<?> create(Type type) {
|
30 |
| - if (type == Boolean.TYPE) return new BooleanAdapter(); |
31 |
| - if (type == Double.TYPE) return new DoubleAdapter(); |
32 |
| - if (type == Float.TYPE) return new FloatAdapter(); |
33 |
| - if (type == Integer.TYPE) return new IntegerAdapter(); |
34 |
| - if (type == Long.TYPE) return new LongAdapter(); |
35 |
| - if (type == Boolean.class) return new BooleanAdapter().nullSafe(); |
36 |
| - if (type == Double.class) return new DoubleAdapter().nullSafe(); |
37 |
| - if (type == Float.class) return new FloatAdapter().nullSafe(); |
38 |
| - if (type == Integer.class) return new IntegerAdapter().nullSafe(); |
39 |
| - if (type == Long.class) return new LongAdapter().nullSafe(); |
40 |
| - if (type == String.class) return new StringAdapter().nullSafe(); |
| 42 | + if (type == Boolean.TYPE) return BOOLEAN_ADAPTER; |
| 43 | + if (type == Double.TYPE) return DOUBLE_ADAPTER; |
| 44 | + if (type == Float.TYPE) return FLOAT_ADAPTER; |
| 45 | + if (type == Integer.TYPE) return INTEGER_ADAPTER; |
| 46 | + if (type == Long.TYPE) return LONG_ADAPTER; |
| 47 | + if (type == Boolean.class) return NULL_SAFE_BOOLEAN; |
| 48 | + if (type == Double.class) return NULL_SAFE_DOUBLE; |
| 49 | + if (type == Float.class) return NULL_SAFE_FLOAT; |
| 50 | + if (type == Integer.class) return NULL_SAFE_INT; |
| 51 | + if (type == Long.class) return NULL_SAFE_LONG; |
| 52 | + if (type == String.class) return STRING_ADAPTER; |
41 | 53 |
|
42 | 54 | return null;
|
43 | 55 | }
|
|
0 commit comments