org.testifyproject.github.dockerjava.api.model.Binds Maven / Gradle / Ivy
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;
@JsonSerialize(using = Binds.Serializer.class)
@JsonDeserialize(using = Binds.Deserializer.class)
public class Binds {
private Bind[] binds;
public Binds(Bind... binds) {
this.binds = binds;
}
public Bind[] getBinds() {
return binds;
}
public static class Serializer extends JsonSerializer {
@Override
public void serialize(Binds binds, JsonGenerator jsonGen, SerializerProvider serProvider) throws IOException,
JsonProcessingException {
//
jsonGen.writeStartArray();
for (Bind bind : binds.getBinds()) {
jsonGen.writeString(bind.toString());
}
jsonGen.writeEndArray();
//
}
}
public static class Deserializer extends JsonDeserializer {
@Override
public Binds org.testifyproject.testifyprojectserialize(JsonParser jsonParser, DeserializationContext org.testifyproject.testifyprojectserializationContext)
throws IOException, JsonProcessingException {
List binds = new ArrayList();
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
for (Iterator it = node.elements(); it.hasNext();) {
JsonNode field = it.next();
binds.add(Bind.parse(field.asText()));
}
return new Binds(binds.toArray(new Bind[0]));
}
}
}