org.addsimplicity.anicetus.io
Class JsonDecoder

java.lang.Object
  extended by org.addsimplicity.anicetus.io.JsonDecoder
All Implemented Interfaces:
TelemetryDecoder

public class JsonDecoder
extends java.lang.Object
implements TelemetryDecoder

The decoder translates a JSON encoded telemetry into a Java object. In addition to decoding the telemetry maps, the decoder will also attempt to decode simple Java beans. It relies upon the application adding packages for searching for types to detect a bean. If it encounters a type it doesn't recognize, it decodes it into a TelemetryState which is just a simple map.

Author:
Dan Pritchett (driveawedge@yahoo.com)

Constructor Summary
JsonDecoder()
           
 
Method Summary
static void addDefaultPackage(java.lang.String pkgName)
          Add a default package to the search list that will be used for decoding JSON.
 GlobalInfo decode(char[] jsonEncoded)
          Convert a character array that represents a JSON encoded object.
 ExceptionHandler getExceptionHandler()
          Return the exception handler in effect for the decoder.
 void setExceptionHandler(ExceptionHandler exceptionHandler)
          Set the exception handler that will receive any exception that occurs during decoding.
 void setSearchPackages(java.lang.String[] packages)
          Add packages to the package search list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonDecoder

public JsonDecoder()
Method Detail

addDefaultPackage

public static void addDefaultPackage(java.lang.String pkgName)
Add a default package to the search list that will be used for decoding JSON. This package will be used for every instance of the decoder.

Parameters:
pkgName - The name of the package to add.

decode

public GlobalInfo decode(char[] jsonEncoded)
Convert a character array that represents a JSON encoded object. The entire object graph will be decoded and returned as the appropriate root telemetry artifact.

Specified by:
decode in interface TelemetryDecoder
Parameters:
jsonEncoded - The encoded JSON object as a character array.
Returns:
the telemetry artifact

getExceptionHandler

public ExceptionHandler getExceptionHandler()
Return the exception handler in effect for the decoder.

Returns:
the exception handler in effect.

setExceptionHandler

public void setExceptionHandler(ExceptionHandler exceptionHandler)
Set the exception handler that will receive any exception that occurs during decoding.

Parameters:
exceptionHandler - The exception handler.

setSearchPackages

public void setSearchPackages(java.lang.String[] packages)
Add packages to the package search list. This list is added to the set as well as the default list. Note that the default entity package is always in the default list.

Parameters:
packages - The list of packages to add.


Copyright © 2009 Add Simplicity. All Rights Reserved.