@Override
   public void serialize(ConfigurationWriter writer, ServerConfiguration configuration) {
      writer.writeStartElement(Element.SERVER);
      writer.writeDefaultNamespace(NAMESPACE + Version.getMajorMinor());
      writeInterfaces(writer, configuration.interfaces);
      writeSocketBindings(writer, configuration.socketBindings);
      writeSecurity(writer, configuration.security());
      writeDataSources(writer, configuration.dataSources());
      writeEndpoints(writer, configuration.endpoints());
      writer.writeEndElement();
   }
@Test
   public void testConfigurationSerialization() throws IOException {
      Properties properties = new Properties();
      properties.put("infinispan.server.config.path", config.getParent().getParent().toString());
      properties.setProperty(Server.INFINISPAN_SERVER_HOME_PATH, Paths.get(System.getProperty("build.directory")).toString());
      properties.setProperty("org.infinispan.test.host.address", "127.0.0.1");
      ParserRegistry registry = new ParserRegistry(Thread.currentThread().getContextClassLoader(), false, properties);
      ConfigurationBuilderHolder holderBefore = registry.parse(config);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      Map<String, Configuration> configurations = new HashMap<>();
      for (Map.Entry<String, ConfigurationBuilder> configuration : holderBefore.getNamedConfigurationBuilders().entrySet()) {
         configurations.put(configuration.getKey(), configuration.getValue().build());
      }
      try (ConfigurationWriter writer = ConfigurationWriter.to(baos).withType(type).clearTextSecrets(true).build()) {
         registry.serialize(writer, holderBefore.getGlobalConfigurationBuilder().build(), configurations);
      }
      log.debug(baos);
      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      ConfigurationBuilderHolder holderAfter = registry.parse(bais, ConfigurationResourceResolvers.DEFAULT, type);
      GlobalConfiguration globalConfigurationBefore = holderBefore.getGlobalConfigurationBuilder().build();
      GlobalConfiguration globalConfigurationAfter = holderAfter.getGlobalConfigurationBuilder().build();
      ServerConfiguration serverBefore = globalConfigurationBefore.module(ServerConfiguration.class);
      ServerConfiguration serverAfter = globalConfigurationAfter.module(ServerConfiguration.class);
      compare(serverBefore.interfaces.interfaces(), serverAfter.interfaces.interfaces());
      compare(serverBefore.socketBindings, serverAfter.socketBindings);
      compare(serverBefore.dataSources, serverAfter.dataSources);
      compare(serverBefore.security.credentialStores(), serverAfter.security.credentialStores());
      compare(serverBefore.security.realms().realms(), serverAfter.security.realms().realms());
      compare(serverBefore.transport(), serverAfter.transport(), org.infinispan.server.configuration.Attribute.SECURITY_REALM.toString());
      compare(serverBefore.endpoints.endpoints(), serverAfter.endpoints.endpoints());

      for (int i = 0; i < serverBefore.endpoints.endpoints().size(); i++) {
         EndpointConfiguration endpointBefore = serverBefore.endpoints.endpoints().get(i);
         EndpointConfiguration endpointAfter = serverAfter.endpoints.endpoints().get(i);

         compare(endpointBefore, endpointAfter);
         compare(endpointBefore.connectors(), endpointAfter.connectors());
         compare(endpointBefore.singlePortRouter(), endpointAfter.singlePortRouter());
      }
   }