Move to Jackson for default json
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m25s

This commit is contained in:
Braydon 2024-04-10 08:20:57 -04:00
parent d11f87e36e
commit d2a54ac828
10 changed files with 21 additions and 50 deletions

@ -64,14 +64,6 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<!-- Exclude the default Jackson dependency -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!-- Redis for caching --> <!-- Redis for caching -->

@ -28,7 +28,6 @@ import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import java.io.File; import java.io.File;
import java.nio.file.Files; import java.nio.file.Files;
@ -38,7 +37,7 @@ import java.util.Objects;
/** /**
* @author Braydon * @author Braydon
*/ */
@SpringBootApplication(exclude = { JacksonAutoConfiguration.class }) @SpringBootApplication
@Slf4j(topic = "RESTfulMC") @Slf4j(topic = "RESTfulMC")
public class RESTfulMC { public class RESTfulMC {
@SneakyThrows @SneakyThrows

@ -38,11 +38,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.info.BuildProperties; import org.springframework.boot.info.BuildProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
/** /**
* The configuration for the app. * The configuration for the app.
@ -50,7 +45,7 @@ import java.util.List;
* @author Braydon * @author Braydon
*/ */
@Configuration @Getter @Configuration @Getter
public class AppConfig implements WebMvcConfigurer { public class AppConfig {
public static AppConfig INSTANCE; public static AppConfig INSTANCE;
public static final Gson GSON = new GsonBuilder() public static final Gson GSON = new GsonBuilder()
.setDateFormat("MM-dd-yyyy HH:mm:ss") .setDateFormat("MM-dd-yyyy HH:mm:ss")
@ -93,27 +88,4 @@ public class AppConfig implements WebMvcConfigurer {
.info(info) .info(info)
.addServersItem(new Server().url(serverPublicUrl).description("The public server URL")); .addServersItem(new Server().url(serverPublicUrl).description("The public server URL"));
} }
/**
* Configure the default HTTP
* message converters to use Gson.
*
* @param converters the converters
*/
@Override
public void configureMessageConverters(@NonNull List<HttpMessageConverter<?>> converters) {
GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
gsonHttpMessageConverter.setGson(gson());
converters.add(gsonHttpMessageConverter);
}
/**
* Our custom Gson instance to use.
*
* @return the Gson instance
*/
@Bean @NonNull
public Gson gson() {
return GSON;
}
} }

@ -23,6 +23,7 @@
*/ */
package me.braydon.mc.model; package me.braydon.mc.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*; import lombok.*;
import me.braydon.mc.common.ColorUtils; import me.braydon.mc.common.ColorUtils;
import me.braydon.mc.service.pinger.MinecraftServerPinger; import me.braydon.mc.service.pinger.MinecraftServerPinger;
@ -67,7 +68,7 @@ public class MinecraftServer {
/** /**
* Player count data for a server. * Player count data for a server.
*/ */
@AllArgsConstructor @Getter @ToString @AllArgsConstructor @Getter @ToString @JsonInclude(JsonInclude.Include.NON_NULL)
public static class Players { public static class Players {
/** /**
* The online players on this server. * The online players on this server.

@ -23,6 +23,7 @@
*/ */
package me.braydon.mc.model; package me.braydon.mc.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*; import lombok.*;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
@ -35,7 +36,7 @@ import java.util.UUID;
*/ */
@AllArgsConstructor @Getter @AllArgsConstructor @Getter
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
@ToString @ToString @JsonInclude(JsonInclude.Include.NON_NULL)
public class Player { public class Player {
/** /**
* The unique id of this player. * The unique id of this player.

@ -101,7 +101,11 @@ public final class Skin {
*/ */
@AllArgsConstructor @Getter @ToString @AllArgsConstructor @Getter @ToString
public enum Part { public enum Part {
HEAD(8, 8, ImageUtils.SKIN_TEXTURE_SIZE / 8, ImageUtils.SKIN_TEXTURE_SIZE / 8); HEAD_TOP(8, 0, ImageUtils.SKIN_TEXTURE_SIZE / 8, ImageUtils.SKIN_TEXTURE_SIZE / 8),
FACE(8, 8, ImageUtils.SKIN_TEXTURE_SIZE / 8, ImageUtils.SKIN_TEXTURE_SIZE / 8),
HEAD_LEFT(0, 8, ImageUtils.SKIN_TEXTURE_SIZE / 8, ImageUtils.SKIN_TEXTURE_SIZE / 8),
HEAD_RIGHT(16, 8, ImageUtils.SKIN_TEXTURE_SIZE / 8, ImageUtils.SKIN_TEXTURE_SIZE / 8),
HEAD_BOTTOM(8, 8, ImageUtils.SKIN_TEXTURE_SIZE / 8, ImageUtils.SKIN_TEXTURE_SIZE / 8);
/** /**
* The coordinates of this part. * The coordinates of this part.

@ -23,6 +23,7 @@
*/ */
package me.braydon.mc.model.cache; package me.braydon.mc.model.cache;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*; import lombok.*;
import me.braydon.mc.model.MinecraftServer; import me.braydon.mc.model.MinecraftServer;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
@ -39,7 +40,7 @@ public final class CachedMinecraftServer implements Serializable {
/** /**
* The id of this cached server. * The id of this cached server.
*/ */
@Id @NonNull private transient final String id; @Id @JsonIgnore @NonNull private final String id;
/** /**
* The cached server. * The cached server.

@ -34,9 +34,9 @@ import me.braydon.mc.model.MinecraftServer;
@Getter @ToString(callSuper = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true) @Getter @ToString(callSuper = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true)
public final class BedrockMinecraftServer extends MinecraftServer { public final class BedrockMinecraftServer extends MinecraftServer {
/** /**
* The unique ID of this server. * The ID of this server.
*/ */
@EqualsAndHashCode.Include @NonNull private final String uniqueId; @EqualsAndHashCode.Include @NonNull private final String id;
/** /**
* The edition of this server. * The edition of this server.
@ -53,11 +53,11 @@ public final class BedrockMinecraftServer extends MinecraftServer {
*/ */
@NonNull private final GameMode gamemode; @NonNull private final GameMode gamemode;
private BedrockMinecraftServer(@NonNull String uniqueId, @NonNull String hostname, String ip, int port, private BedrockMinecraftServer(@NonNull String id, @NonNull String hostname, String ip, int port,
@NonNull Edition edition, @NonNull Version version, @NonNull Players players, @NonNull Edition edition, @NonNull Version version, @NonNull Players players,
@NonNull MOTD motd, @NonNull GameMode gamemode) { @NonNull MOTD motd, @NonNull GameMode gamemode) {
super(hostname, ip, port, players, motd); super(hostname, ip, port, players, motd);
this.uniqueId = uniqueId; this.id = id;
this.edition = edition; this.edition = edition;
this.version = version; this.version = version;
this.gamemode = gamemode; this.gamemode = gamemode;

@ -23,6 +23,7 @@
*/ */
package me.braydon.mc.model.server; package me.braydon.mc.model.server;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import lombok.*; import lombok.*;
import me.braydon.mc.common.JavaMinecraftVersion; import me.braydon.mc.common.JavaMinecraftVersion;
@ -38,7 +39,7 @@ import net.md_5.bungee.chat.ComponentSerializer;
* *
* @author Braydon * @author Braydon
*/ */
@Setter @Getter @ToString(callSuper = true) @Setter @Getter @ToString(callSuper = true) @JsonInclude(JsonInclude.Include.NON_NULL)
public final class JavaMinecraftServer extends MinecraftServer { public final class JavaMinecraftServer extends MinecraftServer {
/** /**
* The version information of this server. * The version information of this server.
@ -114,7 +115,7 @@ public final class JavaMinecraftServer extends MinecraftServer {
/** /**
* Version information for a server. * Version information for a server.
*/ */
@AllArgsConstructor @Getter @ToString @AllArgsConstructor @Getter @ToString @JsonInclude(JsonInclude.Include.NON_NULL)
public static class Version { public static class Version {
/** /**
* The version name of the server. * The version name of the server.

@ -169,7 +169,7 @@ public final class MojangService {
} }
Skin.Part part = EnumUtils.getEnumConstant(Skin.Part.class, partName.toUpperCase()); // The skin part to get Skin.Part part = EnumUtils.getEnumConstant(Skin.Part.class, partName.toUpperCase()); // The skin part to get
if (part == null) { // Default to the head part if (part == null) { // Default to the head part
part = Skin.Part.HEAD; part = Skin.Part.FACE;
} }
if (extension.isBlank()) { // Invalid extension if (extension.isBlank()) { // Invalid extension
throw new BadRequestException("Invalid extension"); throw new BadRequestException("Invalid extension");