com.docmosis.template.population
Class JSONDataProvider

java.lang.Object
  extended by com.docmosis.template.population.MemoryDataProvider
      extended by com.docmosis.template.population.JSONDataProvider
All Implemented Interfaces:
Cleanable, DataProvider, MutableDataProvider, Serializable

public class JSONDataProvider
extends MemoryDataProvider

A MemoryDataProvider that can load itself from JSON formatted data.

See Also:
Serialized Form

Constructor Summary
JSONDataProvider()
           
JSONDataProvider(String jsonString, StringInterceptor[] interceptors)
          Construct a data provider from a JSON string.
 
Method Summary
 String toJSONString()
          Convert this Data Provider into a JSON string.
static String toJSONString(MemoryDataProvider dp)
          Convert the given Data Provider into a JSON string.
 String toStringPretty()
          Convert this Data Provider into a Pretty JSON string.
 
Methods inherited from class com.docmosis.template.population.MemoryDataProvider
addDataProvider, cleanup, finalize, getBoolean, getBooleanKeys, getDataProvider, getDataProviderCount, getDataProviderKeys, getImage, getImageKeys, getRealKey, getString, getStringKeys, hasBooleanKey, hasDataProviderKey, hasImageKey, hasStringKey, setBoolean, setFalse, setImage, setImage, setString, setTrue, toDebugString, toDebugString, toDebugString, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JSONDataProvider

public JSONDataProvider()

JSONDataProvider

public JSONDataProvider(String jsonString,
                        StringInterceptor[] interceptors)
                 throws JSONException
Construct a data provider from a JSON string.

Parameters:
jsonString - the JSON string.
interceptors - an array of interceptors that have the opportunity to interpret the given key and value and add the data to this data provider in a different form.
Throws:
JSONException
Method Detail

toJSONString

public String toJSONString()
                    throws JSONException
Convert this Data Provider into a JSON string.

Returns:
a string containing the JSON content - can be written to a file.
Throws:
JSONException - for serious unexpected errors.
ClassCastException - if any sub data provider of dp is not a MemoryDataProvider (or subclass).

toStringPretty

public String toStringPretty()
Convert this Data Provider into a Pretty JSON string.

Specified by:
toStringPretty in interface DataProvider
Overrides:
toStringPretty in class MemoryDataProvider
Returns:
a string containing the JSON content - can be written to a file.
Throws:
JSONException - for serious unexpected errors.
ClassCastException - if any sub data provider of dp is not a MemoryDataProvider (or subclass).

toJSONString

public static String toJSONString(MemoryDataProvider dp)
                           throws JSONException
Convert the given Data Provider into a JSON string.

Parameters:
dp - the data provider to convert (must be a MemoryDataProvider or subclass).
Returns:
a string containing the JSON content - can be written to a file.
Throws:
JSONException - for serious unexpected errors.
ClassCastException - if any sub data provider of dp is not a MemoryDataProvider (or subclass).


Copyright © 2014–2022 Docmosis Pty Ltd. All rights reserved.