From 592bca234b021098fb28abda96c4e63180a57a08 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Wed, 10 Apr 2024 08:23:38 -0400 Subject: [PATCH] Change default Jackson behaviour to not serialize nulls --- src/main/java/me/braydon/mc/model/MinecraftServer.java | 3 +-- src/main/java/me/braydon/mc/model/Player.java | 3 +-- .../java/me/braydon/mc/model/server/JavaMinecraftServer.java | 5 ++--- src/main/resources/application.yml | 4 ++++ 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/braydon/mc/model/MinecraftServer.java b/src/main/java/me/braydon/mc/model/MinecraftServer.java index 1f463b7..d999feb 100644 --- a/src/main/java/me/braydon/mc/model/MinecraftServer.java +++ b/src/main/java/me/braydon/mc/model/MinecraftServer.java @@ -23,7 +23,6 @@ */ package me.braydon.mc.model; -import com.fasterxml.jackson.annotation.JsonInclude; import lombok.*; import me.braydon.mc.common.ColorUtils; import me.braydon.mc.service.pinger.MinecraftServerPinger; @@ -68,7 +67,7 @@ public class MinecraftServer { /** * Player count data for a server. */ - @AllArgsConstructor @Getter @ToString @JsonInclude(JsonInclude.Include.NON_NULL) + @AllArgsConstructor @Getter @ToString public static class Players { /** * The online players on this server. diff --git a/src/main/java/me/braydon/mc/model/Player.java b/src/main/java/me/braydon/mc/model/Player.java index 93d9d3a..6ac8c68 100644 --- a/src/main/java/me/braydon/mc/model/Player.java +++ b/src/main/java/me/braydon/mc/model/Player.java @@ -23,7 +23,6 @@ */ package me.braydon.mc.model; -import com.fasterxml.jackson.annotation.JsonInclude; import lombok.*; import org.springframework.data.annotation.Id; @@ -36,7 +35,7 @@ import java.util.UUID; */ @AllArgsConstructor @Getter @EqualsAndHashCode(onlyExplicitlyIncluded = true) -@ToString @JsonInclude(JsonInclude.Include.NON_NULL) +@ToString public class Player { /** * The unique id of this player. diff --git a/src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java b/src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java index 8d8ea74..e88e713 100644 --- a/src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java +++ b/src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java @@ -23,7 +23,6 @@ */ package me.braydon.mc.model.server; -import com.fasterxml.jackson.annotation.JsonInclude; import com.google.gson.annotations.SerializedName; import lombok.*; import me.braydon.mc.common.JavaMinecraftVersion; @@ -39,7 +38,7 @@ import net.md_5.bungee.chat.ComponentSerializer; * * @author Braydon */ -@Setter @Getter @ToString(callSuper = true) @JsonInclude(JsonInclude.Include.NON_NULL) +@Setter @Getter @ToString(callSuper = true) public final class JavaMinecraftServer extends MinecraftServer { /** * The version information of this server. @@ -115,7 +114,7 @@ public final class JavaMinecraftServer extends MinecraftServer { /** * Version information for a server. */ - @AllArgsConstructor @Getter @ToString @JsonInclude(JsonInclude.Include.NON_NULL) + @AllArgsConstructor @Getter @ToString public static class Version { /** * The version name of the server. diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d2e4e26..b8b7f1f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -21,6 +21,10 @@ spring: database: 0 auth: "" # Leave blank for no auth + # Don't serialize null values by default with Jackson + jackson: + default-property-inclusion: non_null + # Ignore banner: location: "classpath:banner.txt" \ No newline at end of file