2021-04-29 14:45:18 +00:00
|
|
|
package uulm.teamname.marvelous.gamelibrary.json;
|
2021-04-29 14:40:35 +00:00
|
|
|
|
2021-05-11 04:13:21 +00:00
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2021-04-29 14:40:35 +00:00
|
|
|
import jdk.jshell.spi.ExecutionControl;
|
2021-05-28 12:51:17 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.json.basic.EventMessage;
|
2021-04-29 14:40:35 +00:00
|
|
|
|
|
|
|
/** Contains JSON encoding and decoding.
|
|
|
|
*/
|
|
|
|
public class JSON {
|
2021-05-28 12:51:17 +00:00
|
|
|
/** Deserializes an incoming network message into a {@link EventMessage}.
|
2021-04-29 14:40:35 +00:00
|
|
|
* @param input The JSON to deserialize.
|
2021-04-30 18:54:34 +00:00
|
|
|
* @return The parsed message. */
|
2021-05-28 12:51:17 +00:00
|
|
|
public static EventMessage parse(String input) {
|
|
|
|
EventMessage result = null;
|
2021-05-11 04:13:21 +00:00
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
try {
|
2021-05-28 12:51:17 +00:00
|
|
|
result = mapper.readValue(input, EventMessage.class);
|
2021-05-11 04:13:21 +00:00
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return result;
|
2021-04-29 14:40:35 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 12:51:17 +00:00
|
|
|
/** Serializes a {@link EventMessage} into a JSON string.
|
2021-04-29 14:40:35 +00:00
|
|
|
* @param input The message to serialize.
|
2021-04-30 18:54:34 +00:00
|
|
|
* @return The message as JSON. */
|
2021-05-28 12:51:17 +00:00
|
|
|
public static String stringify(EventMessage input) throws ExecutionControl.NotImplementedException {
|
2021-04-29 14:40:35 +00:00
|
|
|
//TODO: implement JSON.stringify
|
|
|
|
throw new ExecutionControl.NotImplementedException("JSON.stringify is not implemented");
|
|
|
|
}
|
|
|
|
}
|