调整 JSON 序列化的版本

This commit is contained in:
YuCheng Hu 2024-10-22 18:32:21 -04:00
parent 94ed05d9b8
commit 8c43df4bcb
6 changed files with 28 additions and 21 deletions

View File

@ -16,6 +16,11 @@
<option name="name" value="OSSEZ Private Snapshots" />
<option name="url" value="https://repo.ossez.com/repository/maven-snapshots/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven_central" />
<option name="name" value="Maven Central" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />

View File

@ -62,11 +62,6 @@
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>

View File

@ -1,8 +1,10 @@
package com.ossez.discourse.client.service;
import com.fasterxml.jackson.core.StreamReadFeature;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.ossez.discourse.common.exception.DiscourseError;
import com.ossez.discourse.common.exception.DiscourseRuntimeException;
import com.ossez.discourse.common.model.dto.Post;
@ -48,10 +50,10 @@ public class TopicsService extends DiscourseClient {
if (response.code() == HttpStatus.SC_OK) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
discourseTopic = Optional.of(objectMapper.readValue(responseStr, Topic.class));
}
} catch (IOException e) {

View File

@ -70,7 +70,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.36</version>
<version>2.0.16</version>
</dependency>
<dependency>

View File

@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@ -18,7 +19,7 @@ public class Topic {
private String title;
private String fancyTitle;
private Integer postsCount;
private LocalDate createdAt;
private LocalDateTime createdAt;
private Integer views;
private Integer replyCount;
private Integer likeCount;
@ -109,11 +110,11 @@ public class Topic {
this.postsCount = postsCount;
}
public LocalDate getCreatedAt() {
public LocalDateTime getCreatedAt() {
return createdAt;
}
public void setCreatedAt(LocalDate createdAt) {
public void setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt;
}

26
pom.xml
View File

@ -133,11 +133,7 @@
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.13.0</version>
</dependency>
<!-- 测试所用依赖 -->
<dependency>
@ -304,16 +300,17 @@
</dependency>
<!-- JSON -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.14.0</version>
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.17.2</version>
</dependency>
<!-- TEST -->
<dependency>
@ -551,5 +548,12 @@
<!-- </plugin>-->
</plugins>
</build>
<repositories>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
</project>