Allow unicode in events

Change the events deserialization to handle UTF-8 encoding

Change-Id: I73c1a50df5fe365b1ed7d047f58d0e7f67f51d40
This commit is contained in:
Ryan Brandt 2015-04-17 14:51:45 -06:00
parent 8f28398d07
commit 0f249a28cb
1 changed files with 9 additions and 2 deletions

View File

@ -27,7 +27,11 @@ import monasca.common.util.Serialization;
import backtype.storm.tuple.Fields;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.Collections;
import java.util.List;
@ -39,6 +43,7 @@ import java.util.List;
* </ul>
*/
public class EventDeserializer implements TupleDeserializer, Serializable {
private static final Logger logger = LoggerFactory.getLogger(EventDeserializer.class);
private static final long serialVersionUID = -1306620481933667305L;
private static final Fields FIELDS = new Fields("event");
@ -54,9 +59,11 @@ public class EventDeserializer implements TupleDeserializer, Serializable {
@Override
public List<List<?>> deserialize(byte[] tuple) {
try {
String tupleStr = new String(tuple, "UTF-8");
return Collections.<List<?>>singletonList(Collections.singletonList(Serialization
.fromJson(tuple)));
} catch (Exception ignore) {
.fromJson(tupleStr)));
} catch (Exception ex) {
logger.error("Failed to parse event: " + new String(tuple), ex);
return null;
}
}