Code example for JsonParser

Methods: parse

0
	 * Resolve json string do datapackage. 
	 * @param json 
	 * @return 
	 */ 
	private DataPacket parsePackage(String json) {
		JsonParser parser = new JsonParser(); 
		JsonElement e = parser.parse(json); 
 
		String command = e.getAsJsonObject().getAsJsonPrimitive("fn").getAsString();
		 
		Class<? extends Packetable> pojoClass = packetHelper.getClassForPacket(command);
		 
		if(pojoClass == null) {
			throw new InvalidParameterException("'" + command + "' is not a valid data packet!");
		} 
		 
		Packetable payload = (Packetable) new Gson().fromJson(e.getAsJsonObject().getAsJsonObject("p"), pojoClass);
		 
		DataPacket pkg = new DataPacket();
		pkg.setCommand(command);