All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testifyproject.github.dockerjava.api.model.Links Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package org.testifyproject.testifyproject.github.dockerjava.api.model;

import java.org.testifyproject.testifyproject.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.testifyproject.testifyproject.fasterxml.jackson.core.JsonGenerator;
import org.testifyproject.testifyproject.fasterxml.jackson.core.JsonParser;
import org.testifyproject.testifyproject.fasterxml.jackson.core.JsonProcessingException;
import org.testifyproject.testifyproject.fasterxml.jackson.core.ObjectCodec;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.DeserializationContext;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.JsonDeserializer;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.JsonNode;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.JsonSerializer;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.SerializerProvider;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.node.NullNode;

@JsonSerialize(using = Links.Serializer.class)
@JsonDeserialize(using = Links.Deserializer.class)
public class Links {

    private final Link[] links;

    public Links(final Link... links) {
        this.links = links;
    }

    public Links(final List links) {
        this.links = links.toArray(new Link[links.size()]);
    }

    public Link[] getLinks() {
        return links;
    }

    public static class Serializer extends JsonSerializer {

        @Override
        public void serialize(final Links links, final JsonGenerator jsonGen, final SerializerProvider serProvider)
                throws IOException, JsonProcessingException {
            jsonGen.writeStartArray();
            for (final Link link : links.getLinks()) {
                jsonGen.writeString(link.toString());
            }
            jsonGen.writeEndArray();
        }

    }

    public static class Deserializer extends JsonDeserializer {

        @Override
        public Links org.testifyproject.testifyprojectserialize(final JsonParser jsonParser, final DeserializationContext org.testifyproject.testifyprojectserializationContext)
                throws IOException, JsonProcessingException {
            final List binds = new ArrayList();
            final ObjectCodec oc = jsonParser.getCodec();
            final JsonNode node = oc.readTree(jsonParser);
            for (final Iterator it = node.elements(); it.hasNext();) {

                final JsonNode element = it.next();
                if (!element.equals(NullNode.getInstance())) {
                    binds.add(Link.parse(element.asText()));
                }
            }
            return new Links(binds.toArray(new Link[0]));
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy