InstanceSerializer { public static Slime identityToSlime(InstanceIdentity identity) { Slime slime = new Slime(); Cursor root = slime.setObject(); root.setString(PROVIDER_FIELD, identity.provider()); root.setString(NAME_FIELD, identity.service()); root.setString(INSTANCE_ID_FIELD, identity.instanceId()); identity.x509Certificate() .map(X509CertificateUtils::toPem) .ifPresent(pem -> root.setString(X509_CERTIFICATE_FIELD, pem)); return slime; } private  InstanceSerializer(); static InstanceRegistration registrationFromSlime(Slime slime); static InstanceRefresh refreshFromSlime(Slime slime); static Slime identityToSlime(InstanceIdentity identity); static SignedIdentityDocument attestationDataToIdentityDocument(String attestationData);  }
@Test public void serialize_instance_identity() { var certificate = CertificateTester.createCertificate(); var pem = X509CertificateUtils.toPem(certificate); var identity = new InstanceIdentity("provider_prod_us-north-1", "tenant", "node1.example.com", Optional.of(certificate)); var json = "{" + "\"provider\":\"provider_prod_us-north-1\"," + "\"service\":\"tenant\"," + "\"instanceId\":\"node1.example.com\"," + "\"x509Certificate\":\"" + pem.replace("\n", "\\n") + "\"" + "}"; assertEquals(json, asJsonString(InstanceSerializer.identityToSlime(identity))); }