protected SmileEnvelopeEvent(final String eventName, final Granularity granularity, final DateTime eventDateTime, final JsonNode node) { this.eventName = eventName; this.granularity = granularity; this.eventDateTime = eventDateTime; this.root = node; setEventPropertiesFromNode(node); }
@SuppressWarnings("deprecation") public SmileEnvelopeEvent(final JsonNode node) throws IOException { eventName = node.path("eventName").asText(); root = node.get("payload"); if ((root == null || root.size() == 0) || (eventName == null || eventName.isEmpty())) { throw new IOException("Cannot construct a SmileEnvelopeEvent from just a JsonNode unless JsonNode has eventName and payload properties."); } setEventPropertiesFromNode(root); }
/** * The object implements the readExternal method to restore its * contents by calling the methods of DataInput for primitive * types and readObject for objects, strings and arrays. The * readExternal method must read the values in the same sequence * and with the same types as were written by writeExternal. * * @param in the stream to read data from in order to restore the object * @throws java.io.IOException if I/O errors occur */ @Override public void readExternal(final ObjectInput in) throws IOException { // Name of the event first final int smileEventNameBytesSize = in.readInt(); final byte[] eventNameBytes = new byte[smileEventNameBytesSize]; in.readFully(eventNameBytes); eventName = new String(eventNameBytes, NAME_CHARSET); // Then payload final int smilePayloadSize = in.readInt(); final byte[] smilePayload = new byte[smilePayloadSize]; in.readFully(smilePayload); root = parseAsTree(smilePayload); setEventPropertiesFromNode(root); }