Search in sources :

Example 1 with IDataJSONParser

use of permafrost.tundra.data.IDataJSONParser in project Tundra by Permafrost.

the class json method emit.

// ---( server methods )---
public static final void emit(IData pipeline) throws ServiceException {
    // --- <<IS-START(emit)>> ---
    // @subtype unknown
    // @sigtype java 3.5
    // [i] record:0:optional $document
    // [i] - object:1:optional recordWithNoID
    // [i] field:0:optional $encoding
    // [i] field:0:optional $mode {"stream","bytes","string"}
    // [i] field:0:optional $minify? {"false","true"}
    // [o] object:0:optional $content
    IDataCursor cursor = pipeline.getCursor();
    try {
        IData document = IDataHelper.get(cursor, "$document", IData.class);
        Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
        ObjectConvertMode mode = IDataHelper.get(cursor, "$mode", ObjectConvertMode.class);
        boolean minify = IDataHelper.getOrDefault(cursor, "$minify?", Boolean.class, false);
        if (document != null) {
            IDataJSONParser parser = minify ? new IDataJSONParser(!minify) : IDataJSONParser.getInstance();
            IDataHelper.put(cursor, "$content", ObjectHelper.convert(parser.emit(document, charset), charset, mode));
        }
    } catch (IOException ex) {
        ExceptionHelper.raise(ex);
    } finally {
        cursor.destroy();
    }
// --- <<IS-END>> ---
}
Also used : ObjectConvertMode(permafrost.tundra.lang.ObjectConvertMode) Charset(java.nio.charset.Charset) IOException(java.io.IOException) IDataJSONParser(permafrost.tundra.data.IDataJSONParser)

Aggregations

IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1 IDataJSONParser (permafrost.tundra.data.IDataJSONParser)1 ObjectConvertMode (permafrost.tundra.lang.ObjectConvertMode)1