org.addsimplicity.anicetus.io
Class JsonEncoder

java.lang.Object
  extended by org.addsimplicity.anicetus.io.JsonEncoder
All Implemented Interfaces:
TelemetryEncoder

public class JsonEncoder
extends java.lang.Object
implements TelemetryEncoder

The encoder translates telemetry into a JSON string. The object graph is fully exported. In addition to serializing telemetry artifacts, the application can also set classes that are to be treated like beans when serializing. If an object is not a telemetry object and is not a bean, then its toString method is used to generate the value.

Author:
Dan Pritchett (driveawedge@yahoo.com)

Constructor Summary
JsonEncoder()
           
 
Method Summary
 void addBeanType(java.lang.Class<? extends java.lang.Object> bean)
          Add a class to be treated as a bean during encoding.
static void addDefaultBeanType(java.lang.Class<? extends java.lang.Object> beanType)
          Add a default bean type.
 char[] encode(GlobalInfo session)
          Encode the telemetry graph as JSON.
 java.util.Set<java.lang.Class<? extends java.lang.Object>> getBeanTypes()
          Return the current list of bean types in use by the encoder.
 ExceptionHandler getExceptionHandler()
          Return the exception handler currently in effect.
 void setBeanTypes(java.util.Set<java.lang.Class<? extends java.lang.Object>> beanTypes)
          Set the bean types that will be used during JSON encoding.
 void setExceptionHandler(ExceptionHandler exceptionHandler)
          Set the exception handler that will receive exceptions encountered during encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonEncoder

public JsonEncoder()
Method Detail

addDefaultBeanType

public static void addDefaultBeanType(java.lang.Class<? extends java.lang.Object> beanType)
Add a default bean type. This type will be global and apply to all encoders.

Parameters:
beanType - The class of the bean type to add.

addBeanType

public void addBeanType(java.lang.Class<? extends java.lang.Object> bean)
Add a class to be treated as a bean during encoding.

Parameters:
bean - The class of the bean object.

encode

public char[] encode(GlobalInfo session)
Encode the telemetry graph as JSON.

Specified by:
encode in interface TelemetryEncoder
Parameters:
session - The telemetry graph to encode.
Returns:
the JSON string as a character array.

getBeanTypes

public java.util.Set<java.lang.Class<? extends java.lang.Object>> getBeanTypes()
Return the current list of bean types in use by the encoder.

Returns:
the set of bean types.

getExceptionHandler

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

Returns:
the exception handler.

setBeanTypes

public void setBeanTypes(java.util.Set<java.lang.Class<? extends java.lang.Object>> beanTypes)
Set the bean types that will be used during JSON encoding. This set is added to the current set.

Parameters:
beanTypes - The set of bean types to be added to the list.

setExceptionHandler

public void setExceptionHandler(ExceptionHandler exceptionHandler)
Set the exception handler that will receive exceptions encountered during encoding.

Parameters:
exceptionHandler - The exception handler.


Copyright © 2009 Add Simplicity. All Rights Reserved.