Replace Jackson with Gson

This commit is contained in:
Braydon 2024-04-06 22:15:19 -04:00
parent fbdd2fc9a7
commit b8abef9cff
5 changed files with 40 additions and 5 deletions

@ -48,6 +48,14 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<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>
<!-- Redis for caching -->

@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
@ -21,11 +22,11 @@ import java.util.Objects;
/**
* @author Braydon
*/
@SpringBootApplication
@SpringBootApplication(exclude = { JacksonAutoConfiguration.class })
@Slf4j(topic = "RESTfulMC")
public class RESTfulMC {
public static final Gson GSON = new GsonBuilder()
.serializeNulls()
.setDateFormat("MM-dd-yyyy HH:mm:ss")
.create();
/**

@ -0,0 +1,29 @@
package me.braydon.mc.config;
import com.google.gson.Gson;
import me.braydon.mc.RESTfulMC;
import org.springframework.context.annotation.Bean;
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;
/**
* @author Braydon
*/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
gsonHttpMessageConverter.setGson(gson());
converters.add(gsonHttpMessageConverter);
}
@Bean
public Gson gson() {
return RESTfulMC.GSON;
}
}

@ -1,6 +1,5 @@
package me.braydon.mc.model.response;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.http.HttpStatus;
@ -26,7 +25,6 @@ public final class ErrorResponse {
/**
* The timestamp this error occurred.
*/
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
private Date timestamp;
public ErrorResponse(@NonNull HttpStatus status, @NonNull String message) {

@ -1,6 +1,5 @@
package me.braydon.mc.model.token;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Getter;