Skip to content

Commit b02bcbc

Browse files
authored
fix: null handling (#176)
1 parent cdebc2c commit b02bcbc

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/main/java/io/supertokens/storage/postgresql/utils/ConfigMapper.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
package io.supertokens.storage.postgresql.utils;
1818

19-
import com.fasterxml.jackson.annotation.JsonAlias;
20-
import com.fasterxml.jackson.annotation.JsonProperty;
2119
import com.google.gson.JsonElement;
2220
import com.google.gson.JsonNull;
2321
import com.google.gson.JsonObject;
22+
import com.fasterxml.jackson.annotation.JsonProperty;
23+
import com.fasterxml.jackson.annotation.JsonAlias;
2424
import io.supertokens.pluginInterface.exceptions.InvalidConfigException;
2525

2626
import java.lang.annotation.Annotation;
@@ -72,21 +72,9 @@ private static <T> Field findField(Class<T> clazz, String key) {
7272
}
7373

7474
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-
8775
field.setAccessible(true);
8876
Object convertedValue = convertJsonElementToTargetType(value, field.getType(), field.getName());
89-
if (convertedValue != null) {
77+
if (convertedValue != null || isNullable(field.getType())) {
9078
try {
9179
field.set(object, convertedValue);
9280
} catch (IllegalAccessException e) {
@@ -95,6 +83,10 @@ private static <T> void setValue(T object, Field field, JsonElement value) throw
9583
}
9684
}
9785

86+
private static boolean isNullable(Class<?> type) {
87+
return !type.isPrimitive();
88+
}
89+
9890
private static Object convertJsonElementToTargetType(JsonElement value, Class<?> targetType, String fieldName)
9991
throws InvalidConfigException {
10092
// If the value is JsonNull, return null for any type

0 commit comments

Comments
 (0)