public static byte[] toJson(LoadBalancer loadBalancer) {
        Slime slime = new Slime();
        Cursor root = slime.setObject();

        root.setString(idField, loadBalancer.id().serializedForm());
        root.setString(idSeedField, loadBalancer.idSeed());
        loadBalancer.instance().flatMap(LoadBalancerInstance::hostname).ifPresent(hostname -> root.setString(hostnameField, hostname.value()));
        loadBalancer.instance().flatMap(LoadBalancerInstance::ip4Address).ifPresent(ip -> root.setString(lbIpAddressField, ip));
        loadBalancer.instance().flatMap(LoadBalancerInstance::ip6Address).ifPresent(ip -> root.setString(lbIp6AddressField, ip));
        root.setString(stateField, asString(loadBalancer.state()));
        root.setLong(changedAtField, loadBalancer.changedAt().toEpochMilli());
        loadBalancer.instance().flatMap(LoadBalancerInstance::dnsZone).ifPresent(dnsZone -> root.setString(dnsZoneField, dnsZone.id()));
        Cursor portArray = root.setArray(portsField);
        loadBalancer.instance().ifPresent(instance -> instance.ports().forEach(portArray::addLong));
        Cursor networkArray = root.setArray(networksField);
        loadBalancer.instance().ifPresent(instance -> instance.networks().forEach(networkArray::addString));
        Cursor realArray = root.setArray(realsField);
        loadBalancer.instance().ifPresent(instance -> instance.reals().forEach(real -> {
            Cursor realObject = realArray.addObject();
            realObject.setString(hostnameField, real.hostname().value());
            realObject.setString(ipAddressField, real.ipAddress());
            realObject.setLong(portField, real.port());
        }));
        loadBalancer.instance()
                    .map(LoadBalancerInstance::settings)
                    .ifPresent(settings -> toSlime(root.setObject(settingsField), settings));
        loadBalancer.instance().stream()
                    .map(LoadBalancerInstance::serviceIds).flatMap(List::stream)
                    .map(PrivateServiceId::value)
                    .forEach(root.setArray(serviceIdsField)::addString);
        loadBalancer.instance()
                    .map(LoadBalancerInstance::cloudAccount)
                    .filter(cloudAccount -> ! cloudAccount.isUnspecified())
                    .ifPresent(cloudAccount -> root.setString(cloudAccountField, cloudAccount.value()));
        try {
            return SlimeUtils.toJsonBytes(slime);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
Serializer for load balancers.

@author mpolden
node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/LoadBalancerSerializer.java