package net.onrc.onos.core.topology.serializers;

import java.io.IOException;

import net.onrc.onos.core.topology.Device;
import net.onrc.onos.core.topology.Port;
import net.onrc.onos.core.topology.PortEvent.SwitchPort;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.SerializerProvider;
import org.codehaus.jackson.map.ser.std.SerializerBase;

public class DeviceSerializer extends SerializerBase<Device> {

    public DeviceSerializer() {
        super(Device.class);
    }

    @Override
    public void serialize(Device dev, JsonGenerator jsonGenerator,
        SerializerProvider serializerProvider) throws IOException,
        JsonGenerationException {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeNumberField("mac", dev.getMacAddress().toLong());
        jsonGenerator.writeFieldName("attachmentPoints");
        jsonGenerator.writeStartArray();
        for (Port port : dev.getAttachmentPoints()) {
            SwitchPort sp = new SwitchPort(port.getDpid(), port.getNumber());
            jsonGenerator.writeObject(sp);
        }
        jsonGenerator.writeEndArray();
        jsonGenerator.writeEndObject();
    }

}

@@ -159,65 +159,8 @@
 ort;
-%0Aimport net.onrc.onos.core.topology.PortEvent.SwitchPort;
 %0A%0Aim
@@ -360,16 +360,52 @@
 zerBase;
+%0Aimport org.openflow.util.HexString;
 %0A%0Apublic
@@ -781,22 +781,22 @@
 or.write
-Number
+String
 Field(%22m
@@ -826,10 +826,12 @@
 ).to
-Lo
+Stri
 ng()
@@ -1002,53 +1002,182 @@
     
-SwitchPort sp = new SwitchPort(port.getDpid()
+jsonGenerator.writeStartObject();%0A            jsonGenerator.writeStringField(%22dpid%22, HexString.toHexString(port.getDpid()));%0A            jsonGenerator.writeNumberField(%22port%22
 , po
@@ -1228,17 +1228,18 @@
 rite
+End
 Object(
-sp
 );%0A 
@@ -1326,17 +1326,16 @@
 ject();%0A
+
     %7D%0A
-%0A
 %7D%0A

Change device REST API format.