Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.nirima.docker.client.model;
  
 
 
 
 import java.util.Map;

Created by ben on 16/12/13.
 
 @JsonIgnoreProperties(ignoreUnknown=true)
 public class Ports {
     private final Map<StringPortports = new HashMap<StringPort>();
     private Port[] mapping;
 
     private Ports() { }
 
     private void addPort(Port port) {
         .put(port.getPort(), port);
     }
 
     private void addMapping(Port srcPort target) {
         Port p = .get(src);
         if (p==nullreturn;
 //        p.addMapping(target);
     }
 
     @Override
     public String toString() {
         return Objects.toStringHelper(this)
                 .add("ports")
                 .add("mapping")
                 .toString();
     }
 
     public Map<StringPortgetAllPorts(){
         return ;
     }
 
 
     public static class Port{
 
         private final String scheme;
         private final String port;
         private final String hostIp;
         private final String hostPort;
 
         public Port(String scheme_String port_String hostIp_String hostPort_) {
              = scheme_;
              = port_;
              = hostIp_;
              = hostPort_;
         }
 
         public String getScheme() {
             return ;
         }
 
         public String getPort() {
             return ;
         }
 
         public String getHostIp() {
             return ;
         }
 
         public String getHostPort() {
             return ;
         }
 
         public static Port makePort(String fullString hostIpString hostPort) {
             if (full == nullreturn null;
             String[] pieces = full.split("/");
             return new Port(pieces[1], pieces[0], hostIphostPort);
         }
 
         @Override
         public String toString() {
             return "Port{" +
                     "scheme='" +  + '\'' +
                     ", port='" +  + '\'' +
                     ", hostIp='" +  + '\'' +
                    ", hostPort='" +  + '\'' +
                    '}';
        }
    }
    public static class Deserializer extends JsonDeserializer<Ports> {
        @Override
        public Ports deserialize(JsonParser jsonParserDeserializationContext deserializationContextthrows IOExceptionJsonProcessingException {
            Ports out = new Ports();
            ObjectCodec oc = jsonParser.getCodec();
            JsonNode node = oc.readTree(jsonParser);
            for (Iterator<Map.Entry<StringJsonNode>> it = node.fields(); it.hasNext();) {
                Map.Entry<StringJsonNodefield = it.next();
                if (!field.getValue().equals(NullNode.getInstance())) {
                    String hostIp = field.getValue().get(0).get("HostIp").textValue();
                    String hostPort = field.getValue().get(0).get("HostPort").textValue();
                    out.addPort(Port.makePort(field.getKey(), hostIphostPort));
                }
            }
            return out;
        }
    }
    public static class Serializer extends JsonSerializer<Ports> {
        @Override
        public void serialize(Ports portsJsonGenerator jsonGen,
                              SerializerProvider serProviderthrows IOExceptionJsonProcessingException {
            jsonGen.writeStartObject();//{
            for(String portKey : ports.getAllPorts().keySet()){
                Port p = ports.getAllPorts().get(portKey);
                jsonGen.writeFieldName(p.getPort() + "/" + p.getScheme());
                jsonGen.writeStartArray();
                jsonGen.writeStartObject();
                jsonGen.writeStringField("HostIp"p.hostIp);
                jsonGen.writeStringField("HostPort"p.hostPort);
                jsonGen.writeEndObject();
                jsonGen.writeEndArray();
            }
            jsonGen.writeEndObject();//}
        }
    }
New to GrepCode? Check out our FAQ X