com.rapportive.storm.scheme
Class SimpleJSONScheme

java.lang.Object
  extended by com.rapportive.storm.scheme.SimpleJSONScheme
All Implemented Interfaces:
backtype.storm.spout.Scheme, Serializable

public class SimpleJSONScheme
extends Object
implements backtype.storm.spout.Scheme

Deserialisation scheme for JSON values using the json-simple library. Emits one-element tuples with the field name object, containing the parsed JSON value. N.B. if passed invalid JSON it will throw an IllegalArgumentException.

Author:
Sam Stokes (sam@rapportive.com)
See Also:
json-simple, Serialized Form

Constructor Summary
SimpleJSONScheme()
          Create a new JSON deserialisation scheme using UTF-8 as the character encoding.
SimpleJSONScheme(String encoding)
          Create a new JSON deserialisation scheme using the given character encoding.
 
Method Summary
 List<Object> deserialize(byte[] bytes)
          Deserialise a JSON value from bytes using the requested character encoding.
 backtype.storm.tuple.Fields getOutputFields()
          Emits tuples containing only one field, named "object".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleJSONScheme

public SimpleJSONScheme(String encoding)
Create a new JSON deserialisation scheme using the given character encoding.

Parameters:
encoding - character encoding used to deserialise JSON from raw bytes

SimpleJSONScheme

public SimpleJSONScheme()
Create a new JSON deserialisation scheme using UTF-8 as the character encoding.

Method Detail

deserialize

public List<Object> deserialize(byte[] bytes)
Deserialise a JSON value from bytes using the requested character encoding.

Specified by:
deserialize in interface backtype.storm.spout.Scheme
Returns:
a one-element tuple containing the parsed JSON value.
Throws:
IllegalArgumentException - if bytes does not contain valid JSON encoded using the requested encoding.
IllegalStateException - if the requested character encoding is not supported.

getOutputFields

public backtype.storm.tuple.Fields getOutputFields()
Emits tuples containing only one field, named "object".

Specified by:
getOutputFields in interface backtype.storm.spout.Scheme


Copyright © 2011. All Rights Reserved.