feat: added JSON deserialization code to the JSON class
This commit is contained in:
parent
062281fdcb
commit
734445275d
@ -1,6 +1,9 @@
|
|||||||
package uulm.teamname.marvelous.gamelibrary.json;
|
package uulm.teamname.marvelous.gamelibrary.json;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import jdk.jshell.spi.ExecutionControl;
|
import jdk.jshell.spi.ExecutionControl;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||||
import uulm.teamname.marvelous.gamelibrary.json.ingame.MessageStructure;
|
import uulm.teamname.marvelous.gamelibrary.json.ingame.MessageStructure;
|
||||||
|
|
||||||
/** Contains JSON encoding and decoding.
|
/** Contains JSON encoding and decoding.
|
||||||
@ -9,9 +12,17 @@ public class JSON {
|
|||||||
/** Deserializes an incoming network message into a {@link MessageStructure}.
|
/** Deserializes an incoming network message into a {@link MessageStructure}.
|
||||||
* @param input The JSON to deserialize.
|
* @param input The JSON to deserialize.
|
||||||
* @return The parsed message. */
|
* @return The parsed message. */
|
||||||
public static MessageStructure[] parse(String input) throws ExecutionControl.NotImplementedException {
|
public static MessageStructure parse(String input) {
|
||||||
//TODO: implement JSON.parse
|
MessageStructure result = null;
|
||||||
throw new ExecutionControl.NotImplementedException("JSON.parse is not implemented");
|
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.
|
/** Serializes a {@link MessageStructure} into a JSON string.
|
||||||
|
Loading…
Reference in New Issue
Block a user