diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/login/EventMessageDeserializer.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/login/EventMessageDeserializer.java deleted file mode 100644 index 2f3149d..0000000 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/login/EventMessageDeserializer.java +++ /dev/null @@ -1,32 +0,0 @@ -package uulm.teamname.marvelous.gamelibrary.json.login; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.TreeNode; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import uulm.teamname.marvelous.gamelibrary.messages.BasicMessage; -import uulm.teamname.marvelous.gamelibrary.messages.EventMessage; -import uulm.teamname.marvelous.gamelibrary.messages.MessageType; -import uulm.teamname.marvelous.gamelibrary.messages.RequestMessage; - -import java.io.IOException; - -public class EventMessageDeserializer extends JsonDeserializer { - - @Override - public BasicMessage deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { - JsonNode node = p.readValueAsTree(); - - JsonNode subNode; - if ((subNode = node.get("messageType")) != null) { - if (MessageType.valueOf(subNode.textValue()) == MessageType.EVENTS) { - return p.getCodec().treeToValue(node, EventMessage.class); - } else if (MessageType.valueOf(subNode.textValue()) == MessageType.REQUESTS) { - return p.getCodec().treeToValue(node, RequestMessage.class); - } - } - throw new IllegalStateException("EventMessage is actually not an EventMessage"); - } -} diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/login/MessageDeserializer.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/login/MessageDeserializer.java deleted file mode 100644 index fc65cac..0000000 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/login/MessageDeserializer.java +++ /dev/null @@ -1,48 +0,0 @@ -package uulm.teamname.marvelous.gamelibrary.json.login; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import uulm.teamname.marvelous.gamelibrary.messages.*; - -import java.io.IOException; -import java.util.Optional; - -public class MessageDeserializer extends JsonDeserializer { - @Override - public BasicMessage deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { - ObjectCodec codec = p.getCodec(); - JsonNode node = codec.readTree(p); - - var type = Optional.of(node.get("messageType")) - .map(JsonNode::textValue) - .map(MessageType::valueOf); - if (type.isEmpty()) { - throw new IOException("MessageType does not exist"); - } - - BasicMessage message; - - switch (type.get()) { - case HELLO_CLIENT -> message = p.readValueAs(HelloClientMessage.class); - case HELLO_SERVER -> message = p.readValueAs(HelloServerMessage.class); - case ERROR -> message = p.readValueAs(ErrorMessage.class); - case PLAYER_READY -> message = p.readValueAs(PlayerReadyMessage.class); - case RECONNECT -> message = p.readValueAs(ReconnectMessage.class); - case GAME_ASSIGNMENT -> message = p.readValueAs(GameAssignmentMessage.class); - case GENERAL_ASSIGNMENT -> message = p.readValueAs(GeneralAssignmentMessage.class); - case CHARACTER_SELECTION -> message = p.readValueAs(CharacterSelectionMessage.class); - case CONFIRM_SELECTION -> message = p.readValueAs(ConfirmSelectionMessage.class); - case GAME_STRUCTURE -> message = p.readValueAs(GameStructureMessage.class); - case EVENTS -> message = p.readValueAs(EventMessage.class); - case REQUESTS -> message = p.readValueAs(RequestMessage.class); - case GOODBYE_CLIENT -> message = p.readValueAs(GoodbyeClientMessage.class); - default -> throw new IllegalStateException("No MessageType given, which should be impossible"); - } - - return message; - } -} diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicMessage.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicMessage.java index d2dc13e..760ca11 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicMessage.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/BasicMessage.java @@ -5,7 +5,6 @@ import com.fasterxml.jackson.annotation.JsonSubTypes.Type; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonTypeResolver; -import uulm.teamname.marvelous.gamelibrary.json.login.MessageDeserializer; import java.util.Objects; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/EventMessage.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/EventMessage.java index 685d921..3d7dd17 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/EventMessage.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/EventMessage.java @@ -3,7 +3,6 @@ package uulm.teamname.marvelous.gamelibrary.messages; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import uulm.teamname.marvelous.gamelibrary.events.Event; -import uulm.teamname.marvelous.gamelibrary.json.login.EventMessageDeserializer; import java.util.Arrays; import java.util.HashMap; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/GameAssignmentMessage.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/GameAssignmentMessage.java index 41a5168..454b869 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/GameAssignmentMessage.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/messages/GameAssignmentMessage.java @@ -3,7 +3,6 @@ package uulm.teamname.marvelous.gamelibrary.messages; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig; import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties; -import uulm.teamname.marvelous.gamelibrary.json.login.GameAssignmentDeserializer; import java.util.Arrays; import java.util.Objects; diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java index 98b99db..964ca86 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java @@ -164,7 +164,7 @@ class GameLogicTest { server.startGame(player1Selection, player2Selection); - System.out.println(server.toString()); + System.out.println(server); }