@Test public void testDeserializeItemWithoutIpv4() throws Exception { String input = getPayload(NULL, IPV6_VALUE); HostIPs result = testee.deserialize(input); Assert.assertNull(result.getIpV4Address()); Assert.assertEquals(IPV6_VALUE, result.getIpV6Address()); }
@Override public HostIPs deserialize(String data) throws SerializerException { try { HostIPs hostIPs; JSONObject object = new JSONObject(data); if (hasPath(object, HOST_PAYLOAD_NAME, HOST_PARAMETERS_NAME, IPV6_ADDRESS_FIELD_NAME)) { JSONObject parameters = object.getJSONObject(HOST_PAYLOAD_NAME).getJSONObject(HOST_PARAMETERS_NAME); hostIPs = new HostIPs( getStringValueOrNull(parameters, IPV4_ADDRESS_FIELD_NAME), getStringValueOrNull(parameters, IPV6_ADDRESS_FIELD_NAME), getStringValueOrNull(parameters, WEIGHT_FIELD_NAME)); } else { String weight = null; if (hasPath(object, HOST_PAYLOAD_NAME, HOST_PARAMETERS_NAME, "weight")) { JSONObject parameters = object.getJSONObject(HOST_PAYLOAD_NAME).getJSONObject(HOST_PARAMETERS_NAME); weight = getStringValueOrNull(parameters, WEIGHT_FIELD_NAME); } hostIPs = new HostIPs(object.getString(OLD_ADDRESS_FIELD_NAME), null, weight); } return hostIPs; } catch (JSONException e) { throw new SerializerException("failed to parse host " + data, e); } }
ServiceDiscoveryHostJsonSerializer implements ServiceDiscoveryHostDeserializer { @Override public HostIPs deserialize(String data) throws SerializerException { try { HostIPs hostIPs; JSONObject object = new JSONObject(data); if (hasPath(object, HOST_PAYLOAD_NAME, HOST_PARAMETERS_NAME, IPV6_ADDRESS_FIELD_NAME)) { JSONObject parameters = object.getJSONObject(HOST_PAYLOAD_NAME).getJSONObject(HOST_PARAMETERS_NAME); hostIPs = new HostIPs( getStringValueOrNull(parameters, IPV4_ADDRESS_FIELD_NAME), getStringValueOrNull(parameters, IPV6_ADDRESS_FIELD_NAME), getStringValueOrNull(parameters, WEIGHT_FIELD_NAME)); } else { String weight = null; if (hasPath(object, HOST_PAYLOAD_NAME, HOST_PARAMETERS_NAME, "weight")) { JSONObject parameters = object.getJSONObject(HOST_PAYLOAD_NAME).getJSONObject(HOST_PARAMETERS_NAME); weight = getStringValueOrNull(parameters, WEIGHT_FIELD_NAME); } hostIPs = new HostIPs(object.getString(OLD_ADDRESS_FIELD_NAME), null, weight); } return hostIPs; } catch (JSONException e) { throw new SerializerException("failed to parse host " + data, e); } } }
ServiceDiscoveryHostJsonSerializer implements ServiceDiscoveryHostDeserializer { @Override public HostIPs deserialize(String data) throws SerializerException { try { HostIPs hostIPs; JSONObject object = new JSONObject(data); if (hasPath(object, HOST_PAYLOAD_NAME, HOST_PARAMETERS_NAME, IPV6_ADDRESS_FIELD_NAME)) { JSONObject parameters = object.getJSONObject(HOST_PAYLOAD_NAME).getJSONObject(HOST_PARAMETERS_NAME); hostIPs = new HostIPs( getStringValueOrNull(parameters, IPV4_ADDRESS_FIELD_NAME), getStringValueOrNull(parameters, IPV6_ADDRESS_FIELD_NAME), getStringValueOrNull(parameters, WEIGHT_FIELD_NAME)); } else { String weight = null; if (hasPath(object, HOST_PAYLOAD_NAME, HOST_PARAMETERS_NAME, "weight")) { JSONObject parameters = object.getJSONObject(HOST_PAYLOAD_NAME).getJSONObject(HOST_PARAMETERS_NAME); weight = getStringValueOrNull(parameters, WEIGHT_FIELD_NAME); } hostIPs = new HostIPs(object.getString(OLD_ADDRESS_FIELD_NAME), null, weight); } return hostIPs; } catch (JSONException e) { throw new SerializerException("failed to parse host " + data, e); } }  }
ServiceDiscoveryHostJsonSerializer implements ServiceDiscoveryHostDeserializer { @Override public HostIPs deserialize(String data) throws SerializerException { try { HostIPs hostIPs; JSONObject object = new JSONObject(data); if (hasPath(object, HOST_PAYLOAD_NAME, HOST_PARAMETERS_NAME, IPV6_ADDRESS_FIELD_NAME)) { JSONObject parameters = object.getJSONObject(HOST_PAYLOAD_NAME).getJSONObject(HOST_PARAMETERS_NAME); hostIPs = new HostIPs( getStringValueOrNull(parameters, IPV4_ADDRESS_FIELD_NAME), getStringValueOrNull(parameters, IPV6_ADDRESS_FIELD_NAME), getStringValueOrNull(parameters, WEIGHT_FIELD_NAME)); } else { String weight = null; if (hasPath(object, HOST_PAYLOAD_NAME, HOST_PARAMETERS_NAME, "weight")) { JSONObject parameters = object.getJSONObject(HOST_PAYLOAD_NAME).getJSONObject(HOST_PARAMETERS_NAME); weight = getStringValueOrNull(parameters, WEIGHT_FIELD_NAME); } hostIPs = new HostIPs(object.getString(OLD_ADDRESS_FIELD_NAME), null, weight); } return hostIPs; } catch (JSONException e) { throw new SerializerException("failed to parse host " + data, e); } }  @Override HostIPs deserialize(String data); }
ServiceDiscoveryHostJsonSerializer implements ServiceDiscoveryHostDeserializer { @Override public HostIPs deserialize(String data) throws SerializerException { try { HostIPs hostIPs; JSONObject object = new JSONObject(data); if (hasPath(object, HOST_PAYLOAD_NAME, HOST_PARAMETERS_NAME, IPV6_ADDRESS_FIELD_NAME)) { JSONObject parameters = object.getJSONObject(HOST_PAYLOAD_NAME).getJSONObject(HOST_PARAMETERS_NAME); hostIPs = new HostIPs( getStringValueOrNull(parameters, IPV4_ADDRESS_FIELD_NAME), getStringValueOrNull(parameters, IPV6_ADDRESS_FIELD_NAME), getStringValueOrNull(parameters, WEIGHT_FIELD_NAME)); } else { String weight = null; if (hasPath(object, HOST_PAYLOAD_NAME, HOST_PARAMETERS_NAME, "weight")) { JSONObject parameters = object.getJSONObject(HOST_PAYLOAD_NAME).getJSONObject(HOST_PARAMETERS_NAME); weight = getStringValueOrNull(parameters, WEIGHT_FIELD_NAME); } hostIPs = new HostIPs(object.getString(OLD_ADDRESS_FIELD_NAME), null, weight); } return hostIPs; } catch (JSONException e) { throw new SerializerException("failed to parse host " + data, e); } }  @Override HostIPs deserialize(String data); static final String IPV4_ADDRESS_FIELD_NAME; static final String IPV6_ADDRESS_FIELD_NAME; static final String WEIGHT_FIELD_NAME; static final String OLD_ADDRESS_FIELD_NAME; }