EndpointCertificateMetadataSerializer { public static Slime toSlime(EndpointCertificateMetadata metadata) { Slime slime = new Slime(); Cursor object = slime.setObject(); object.setString(keyNameField, metadata.keyName()); object.setString(certNameField, metadata.certName()); object.setLong(versionField, metadata.version()); object.setLong(lastRequestedField, metadata.lastRequested()); metadata.request_id().ifPresent(id -> object.setString(requestIdField, id)); metadata.requestedDnsSans().ifPresent(sans -> { Cursor cursor = object.setArray(requestedDnsSansField); sans.forEach(cursor::addString); }); metadata.issuer().ifPresent(id -> object.setString(issuerField, id)); return slime; }  static Slime toSlime(EndpointCertificateMetadata metadata); static EndpointCertificateMetadata fromSlime(Inspector inspector); static EndpointCertificateMetadata fromJsonString(String zkData);  }
@Test public void serialize() { assertEquals( "{\"keyName\":\"keyName\",\"certName\":\"certName\",\"version\":1,\"lastRequested\":0}", EndpointCertificateMetadataSerializer.toSlime(sample).toString()); }
@Test public void serializeWithRequestMetadata() { assertEquals( "{\"keyName\":\"keyName\",\"certName\":\"certName\",\"version\":1,\"lastRequested\":0,\"requestId\":\"requestId\",\"requestedDnsSans\":[\"SAN1\",\"SAN2\"],\"issuer\":\"issuer\"}", EndpointCertificateMetadataSerializer.toSlime(sampleWithRequestMetadata).toString()); }