根据 https://www.isharkfly.com/t/jackson-snake-case/15034 内容,对类进行重新规划。

This commit is contained in:
YuCheng Hu 2023-10-06 12:52:55 -04:00
parent 259050ba8d
commit 2a3f605b31
8 changed files with 20 additions and 2 deletions

View File

@ -53,7 +53,7 @@ public class PostsService extends DiscourseClient {
if (response.code() == HttpStatus.SC_OK) {
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
// objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
post = Optional.of(objectMapper.readValue(responseStr, Post.class));
}
} catch (IOException e) {

View File

@ -31,7 +31,7 @@ public class PostsServiceTest extends TestBase {
* @throws DiscourseErrorException
*/
@Test
public void testCreatePost() throws DiscourseErrorException {
public void testGetPost() throws DiscourseErrorException {
log.debug("Create WeChat Offical Account Menun Test");
log.debug("{}", postsService.getPost(Long.valueOf("1245")).get().getRaw());

View File

@ -1,10 +1,13 @@
package com.ossez.discourse.common.model.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import java.io.Serializable;
import java.util.List;
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class Creation implements Serializable {
private static final long serialVersionUID = 3741976827910675760L;

View File

@ -1,7 +1,10 @@
package com.ossez.discourse.common.model.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class Post {
@JsonProperty(value = "id", required = true)

View File

@ -1,9 +1,12 @@
package com.ossez.discourse.common.model.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import java.io.Serializable;
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class PostCreation extends Creation implements Serializable {
private static final long serialVersionUID = 5896160842728180229L;

View File

@ -1,10 +1,13 @@
package com.ossez.discourse.common.model.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import java.io.Serializable;
import java.util.List;
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class PostStream implements Serializable {
private static final long serialVersionUID = 7382606905010995326L;
private List<Post> posts;

View File

@ -1,6 +1,8 @@
package com.ossez.discourse.common.model.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import java.io.Serializable;
@ -9,6 +11,7 @@ import java.io.Serializable;
*
* @author YuCheng Hu
*/
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class PostUpdate implements Serializable {
private static final long serialVersionUID = -227183546475863573L;

View File

@ -1,9 +1,12 @@
package com.ossez.discourse.common.model.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import java.util.List;
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class Topic {
private PostStream postStream;