diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java index eb67bd1..5dfc5fe 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java @@ -1,6 +1,9 @@ package uulm.teamname.marvelous.gamelibrary.json; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import jdk.jshell.spi.ExecutionControl; +import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.json.ingame.MessageStructure; /** Contains JSON encoding and decoding. @@ -9,9 +12,17 @@ public class JSON { /** Deserializes an incoming network message into a {@link MessageStructure}. * @param input The JSON to deserialize. * @return The parsed message. */ - public static MessageStructure[] parse(String input) throws ExecutionControl.NotImplementedException { - //TODO: implement JSON.parse - throw new ExecutionControl.NotImplementedException("JSON.parse is not implemented"); + public static MessageStructure parse(String input) { + MessageStructure result = null; + ObjectMapper mapper = new ObjectMapper(); + try { + result = mapper.readValue(input, MessageStructure.class); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return result; + + //TODO: write custom deserializer for Entities because of PID and ID separately (stupid idea indeed) } /** Serializes a {@link MessageStructure} into a JSON string.