Skip to content

Commit 23e8320

Browse files
Chaho12mosabua
authored andcommitted
Improve UserInfo serialization to handle absent values
1 parent 56e33c5 commit 23e8320

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

gateway-ha/src/main/java/io/trino/gateway/ha/router/TrinoRequestUser.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,23 @@ public UserInfoJsonSerializer(Class<Optional<UserInfo>> t)
267267
public void serialize(Optional<UserInfo> userInfo, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
268268
throws IOException
269269
{
270-
userInfo.ifPresent(u -> {
271-
try {
272-
jsonGenerator.writeString(u.toJSONString());
273-
}
274-
catch (IOException e) {
275-
log.error(e, "Error serializing userInfo");
276-
}
277-
});
270+
userInfo.ifPresentOrElse(
271+
u -> {
272+
try {
273+
jsonGenerator.writeString(u.toJSONString());
274+
}
275+
catch (IOException e) {
276+
log.error(e, "Error serializing userInfo");
277+
}
278+
},
279+
() -> {
280+
try {
281+
jsonGenerator.writeNull();
282+
}
283+
catch (IOException e) {
284+
log.error(e, "Error writing null for absent userInfo");
285+
}
286+
});
278287
}
279288
}
280289
}

0 commit comments

Comments
 (0)