16
16
17
17
package io .supertokens .storage .postgresql .utils ;
18
18
19
- import com .fasterxml .jackson .annotation .JsonAlias ;
20
- import com .fasterxml .jackson .annotation .JsonProperty ;
21
19
import com .google .gson .JsonElement ;
22
20
import com .google .gson .JsonNull ;
23
21
import com .google .gson .JsonObject ;
22
+ import com .fasterxml .jackson .annotation .JsonProperty ;
23
+ import com .fasterxml .jackson .annotation .JsonAlias ;
24
24
import io .supertokens .pluginInterface .exceptions .InvalidConfigException ;
25
25
26
26
import java .lang .annotation .Annotation ;
@@ -72,21 +72,9 @@ private static <T> Field findField(Class<T> clazz, String key) {
72
72
}
73
73
74
74
private static <T > void setValue (T object , Field field , JsonElement value ) throws InvalidConfigException {
75
- boolean foundAnnotation = false ;
76
- for (Annotation a : field .getAnnotations ()) {
77
- if (a .toString ().contains ("JsonProperty" )) {
78
- foundAnnotation = true ;
79
- break ;
80
- }
81
- }
82
-
83
- if (!foundAnnotation ) {
84
- return ;
85
- }
86
-
87
75
field .setAccessible (true );
88
76
Object convertedValue = convertJsonElementToTargetType (value , field .getType (), field .getName ());
89
- if (convertedValue != null ) {
77
+ if (convertedValue != null || isNullable ( field . getType ()) ) {
90
78
try {
91
79
field .set (object , convertedValue );
92
80
} catch (IllegalAccessException e ) {
@@ -95,6 +83,10 @@ private static <T> void setValue(T object, Field field, JsonElement value) throw
95
83
}
96
84
}
97
85
86
+ private static boolean isNullable (Class <?> type ) {
87
+ return !type .isPrimitive ();
88
+ }
89
+
98
90
private static Object convertJsonElementToTargetType (JsonElement value , Class <?> targetType , String fieldName )
99
91
throws InvalidConfigException {
100
92
// If the value is JsonNull, return null for any type
0 commit comments