class EthernetCodec extends JsonCodec<Ethernet> {

    @Override
    public ObjectNode encode(Ethernet ethernet, CodecContext context) {
        checkNotNull(ethernet, "Ethernet cannot be null");

        final ObjectNode result = context.mapper().createObjectNode()
                .put("vlanId", ethernet.getVlanID())
                .put("etherType", ethernet.getEtherType())
                .put("priorityCode", ethernet.getPriorityCode())
                .put("pad", ethernet.isPad());

        if (ethernet.getDestinationMAC() != null) {
            result.put("destMac",
                       ethernet.getDestinationMAC().toString());
        }

        if (ethernet.getSourceMAC() != null) {
            result.put("srcMac",
                       ethernet.getSourceMAC().toString());
        }

        return result;
    }

}