fix json type
This commit is contained in:
parent
07af183e7f
commit
c0bd1fe6df
|
|
@ -1,9 +1,12 @@
|
||||||
package com.zhangshu.chat.demo.constant;
|
package com.zhangshu.chat.demo.constant;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum EAgoraEventType {
|
public enum EAgoraEventType {
|
||||||
|
|
@ -24,4 +27,9 @@ public enum EAgoraEventType {
|
||||||
private final int type;
|
private final int type;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public static EAgoraEventType getByType(int type) {
|
||||||
|
return Arrays.stream(EAgoraEventType.values()).filter(v -> v.type == type).findFirst().orElse(channel_create);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.zhangshu.chat.demo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.zhangshu.chat.demo.constant.EAgoraEventType;
|
||||||
|
import com.zhangshu.chat.demo.dto.AgoraEventDto;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class EventTest {
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
public void test() {
|
||||||
|
String str = "{\"eventType\":101}";
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
// AgoraEventDto agoraEventDto = mapper.readValue(str, AgoraEventDto.class);
|
||||||
|
AgoraEventDto agoraEventDto = new AgoraEventDto();
|
||||||
|
agoraEventDto.setEventType(EAgoraEventType.audience_join_channel);
|
||||||
|
String s = mapper.writeValueAsString(agoraEventDto);
|
||||||
|
System.out.println(s);
|
||||||
|
AgoraEventDto agoraEventDto2 = mapper.readValue(s, AgoraEventDto.class);
|
||||||
|
System.out.println(mapper.writeValueAsString(agoraEventDto2));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue