Skip to content

Commit

Permalink
Improve UserInfo serialization to handle absent values
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaho12 authored and mosabua committed Sep 9, 2024
1 parent 56e33c5 commit 23e8320
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,23 @@ public UserInfoJsonSerializer(Class<Optional<UserInfo>> t)
public void serialize(Optional<UserInfo> userInfo, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
throws IOException
{
userInfo.ifPresent(u -> {
try {
jsonGenerator.writeString(u.toJSONString());
}
catch (IOException e) {
log.error(e, "Error serializing userInfo");
}
});
userInfo.ifPresentOrElse(
u -> {
try {
jsonGenerator.writeString(u.toJSONString());
}
catch (IOException e) {
log.error(e, "Error serializing userInfo");
}
},
() -> {
try {
jsonGenerator.writeNull();
}
catch (IOException e) {
log.error(e, "Error writing null for absent userInfo");
}
});
}
}
}

0 comments on commit 23e8320

Please sign in to comment.