@@ -0,0 +1,2222 @@
+package edu.teco.dnd.util;%0A%0Aimport java.lang.reflect.Type;%0Aimport java.net.InetSocketAddress;%0A%0Aimport org.apache.logging.log4j.LogManager;%0Aimport org.apache.logging.log4j.Logger;%0A%0Aimport com.google.gson.JsonDeserializationContext;%0Aimport com.google.gson.JsonDeserializer;%0Aimport com.google.gson.JsonElement;%0Aimport com.google.gson.JsonObject;%0Aimport com.google.gson.JsonParseException;%0Aimport com.google.gson.JsonPrimitive;%0Aimport com.google.gson.JsonSerializationContext;%0Aimport com.google.gson.JsonSerializer;%0A%0A/**%0A * A Gson adapter that handles InetSocketAddresses.%0A *%0A * @author Philipp Adolf%0A */%0Apublic class InetSocketAddressAdapter implements JsonSerializer%3CInetSocketAddress%3E,%0A%09JsonDeserializer%3CInetSocketAddress%3E %7B%0A%09/**%0A%09 * The logger for this class.%0A%09 */%0A%09private static final Logger LOGGER = LogManager.getLogger(InetSocketAddressAdapter.class);%0A%0A%09@Override%0A%09public InetSocketAddress deserialize(final JsonElement json, final Type typeOfT,%0A%09%09%09final JsonDeserializationContext context) throws JsonParseException %7B%0A%09%09LOGGER.entry(json, typeOfT, context);%0A%09%09if (!json.isJsonObject()) %7B%0A%09%09%09LOGGER.exit();%0A%09%09%09throw new JsonParseException(%22not a JSON object%22);%0A%09%09%7D%0A%09%09final JsonObject obj = (JsonObject) json;%0A%09%09final JsonElement address = obj.get(%22address%22);%0A%09%09final JsonElement port = obj.get(%22port%22);%0A%09%09if (address == null %7C%7C port == null) %7B%0A%09%09%09LOGGER.exit();%0A%09%09%09throw new JsonParseException(%22address/port missing%22);%0A%09%09%7D%0A%09%09if (!address.isJsonPrimitive() %7C%7C !((JsonPrimitive) address).isString()) %7B%0A%09%09%09LOGGER.exit();%0A%09%09%09throw new JsonParseException(%22address is not a string%22);%0A%09%09%7D%0A%09%09if (!port.isJsonPrimitive() %7C%7C !((JsonPrimitive) port).isNumber()) %7B%0A%09%09%09LOGGER.exit();%0A%09%09%09throw new JsonParseException(%22port is not a number%22);%0A%09%09%7D%0A%09%09final InetSocketAddress isa = new InetSocketAddress(address.getAsString(), port.getAsInt());%0A%09%09LOGGER.exit(isa);%0A%09%09return isa;%0A%09%7D%0A%0A%09@Override%0A%09public JsonElement serialize(final InetSocketAddress src, final Type typeOfSrc,%0A%09%09%09final JsonSerializationContext context) %7B%0A%09%09LOGGER.entry(src, typeOfSrc, context);%0A%09%09final JsonObject obj = new JsonObject();%0A%09%09obj.addProperty(%22address%22, src.getHostName());%0A%09%09obj.addProperty(%22port%22, src.getPort());%0A%09%09LOGGER.exit(obj);%0A%09%09return obj;%0A%09%7D%0A%0A%7D%0A

Add InetSocketAddressAdapter