Skip to content

Commit

Permalink
Fixes ZMQ Messaging to use JSON Encoding
Browse files Browse the repository at this point in the history
Part (1/3) for edgexfoundry/export-distro#23

Signed-off-by: Tyler_Cox <tyler_cox@dell.com>
  • Loading branch information
trcox committed Oct 20, 2017
1 parent 9481bb3 commit 6ec9ae9
Showing 1 changed file with 6 additions and 3 deletions.
Expand Up @@ -18,6 +18,7 @@

package org.edgexfoundry.messaging.impl;

import com.google.gson.Gson;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutput;
Expand Down Expand Up @@ -83,16 +84,18 @@ private void getPublisher() {
}

/**
* Serialize the event to a byte array
* Encode the event as JSON and send to a byte array
*
* @param Event
* @return serialized byte array
* @return JSON encoded byte array
* @throws IOException
*/
private byte[] toByteArray(Event event) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (ObjectOutput out = new ObjectOutputStream(bos)) {
out.writeObject(event);
Gson gson = new Gson();
String eventString = gson.toJson(event);
out.writeObject(eventString);
return bos.toByteArray();
}
}
Expand Down

0 comments on commit 6ec9ae9

Please sign in to comment.