Gamelib/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java

34 lines
1.3 KiB
Java
Raw Normal View History

2021-04-29 14:45:18 +00:00
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.
*/
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) {
MessageStructure result = null;
ObjectMapper mapper = new ObjectMapper();
try {
result = mapper.readValue(input, MessageStructure.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return result;
}
/** Serializes a {@link MessageStructure} into a JSON string.
* @param input The message to serialize.
* @return The message as JSON. */
public static String stringify(MessageStructure input) throws ExecutionControl.NotImplementedException {
//TODO: implement JSON.stringify
throw new ExecutionControl.NotImplementedException("JSON.stringify is not implemented");
}
}