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;
|
||||
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user