objectmapper patch x4

This commit is contained in:
Michael Wain 2024-07-08 23:03:51 +03:00
parent 06679f1136
commit d06b004526

View File

@ -9,6 +9,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator; import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator;
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator; import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.TextMessage;
@ -36,12 +37,13 @@ public class GameRoom {
private final ObjectMapper om; private final ObjectMapper om;
public GameRoom(List<RoomPlayer> players, UserServiceImpl userService) { public GameRoom(List<RoomPlayer> players, UserServiceImpl userService) {
PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder() /*PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator.builder()
.allowIfSubType("com.alterdekim.game.component.game.DialogButtonsList") .allowIfSubType("com.alterdekim.game.component.game.DialogButtonsList")
.allowIfSubType("java.util.ArrayList") .allowIfSubType("java.util.ArrayList")
.build(); .build();*/
this.om = new ObjectMapper(); this.om = new ObjectMapper();
this.om.activateDefaultTyping(ptv, ObjectMapper.DefaultTyping.NON_FINAL); //this.om.activateDefaultTyping(ptv, ObjectMapper.DefaultTyping.NON_FINAL);
this.om.activateDefaultTyping(new LaissezFaireSubTypeValidator(), ObjectMapper.DefaultTyping.EVERYTHING);
this.userService = userService; this.userService = userService;
this.players = players.stream() this.players = players.stream()
.map(p -> new GamePlayer(p.getUserId(), userService.findById(p.getUserId()).getDisplayName(), 0, new Chip(p.getUserId(), 0, 0, "#000000"))) .map(p -> new GamePlayer(p.getUserId(), userService.findById(p.getUserId()).getDisplayName(), 0, new Chip(p.getUserId(), 0, 0, "#000000")))