Example usage for com.fasterxml.jackson.jr.ob JSON std

List of usage examples for com.fasterxml.jackson.jr.ob JSON std

Introduction

In this page you can find the example usage for com.fasterxml.jackson.jr.ob JSON std.

Prototype

JSON std

To view the source code for com.fasterxml.jackson.jr.ob JSON std.

Click Source Link

Document

Singleton instance with standard, default configuration.

Usage

From source file:ws.util.AbstractJSONCoder.java

@Override
public boolean willDecode(String json) {
    //            logger.log(Level.INFO, new StringBuilder()
    //                  .append("[coder] will decoding..")
    //                  .toString());
    try {/*ww  w  . j  a v a2s  .c o  m*/
        JSON.std.beanFrom(type, json);
        //                  logger.log(Level.INFO, new StringBuilder()
        //                        .append("[coder] OK.. return true")
        //                        .toString());
        return true;
    } catch (IOException e) {
        logger.log(Level.SEVERE, new StringBuilder().append("[coder] NG.. return false").toString());
        logger.log(Level.SEVERE, e.toString());
        return false;
    }

}

From source file:com.asprise.imaging.core.Request.java

public static Request fromJson(String spec) throws IOException {
    JsonParser parser = new JsonFactory().enable(JsonParser.Feature.ALLOW_COMMENTS).createParser(spec);
    Map<Object, Object> json = JSON.std.mapFrom(parser);

    Request request = new Request();
    request.id = JsonUtils.attrValue(json, "request_id", null);
    request.processImagesAfterAllScans = "after-all-scans"
            .equals(JsonUtils.attrValue(json, "processing_strategy", null));
    request.promptScanMore = JsonUtils.attrValueAsBoolean(json, "prompt_scan_more", false);
    request.discardBlankPages = JsonUtils.attrValueAsBoolean(json, "discard_blank_pages", false);
    request.blankPageThreshold = JsonUtils.attrValueAsDouble(json, "blank_page_threshold",
            DEFAULT_BLANK_PAGE_THRESHOLD);
    request.blankPageMarginPercent = JsonUtils.attrValueAsInt(json, "blank_page_margin_percent",
            DEFAULT_BLANK_PAGE_MARGIN_PERCENT);
    request.recognizeBarcodes = JsonUtils.attrValueAsBoolean(json, "recognize_barcodes", false);

    request.useAspriseDialog = JsonUtils.attrValueAsBoolean(json, "use_asprise_dialog", null);
    request.showScannerUI = JsonUtils.attrValueAsBoolean(json, "show_scanner_ui", null);
    request.modalScannerUI = JsonUtils.attrValueAsBoolean(json, "modal_scanner_ui", null);
    request.dialogWidth = JsonUtils.attrValueAsInt(json, "dialog_width", -1);
    request.dialogHeight = JsonUtils.attrValueAsInt(json, "dialog_height", -1);
    request.sourceName = JsonUtils.attrValue(json, "source_name", null);

    Map caps = (Map) json.get("twain_cap_setting");
    if (caps != null) {
        request.twainCapSetting.putAll(caps);
    }/*w  ww  .  jav  a2s. c  o  m*/

    List outputs = (List) json.get("output_settings");
    for (int i = 0; outputs != null && i < outputs.size(); i++) {
        request.outputItems.add(RequestOutputItem.fromJsonMap((Map) outputs.get(i)));
    }

    if (json.get("retrieve_caps") instanceof Collection) {
        request.retrieveCaps.addAll((Collection<? extends String>) json.get("retrieve_caps"));
    }

    if (json.get("retrieve_extended_image_attrs") instanceof Collection) {
        request.retrieveExtendedImageAttributes
                .addAll((Collection<? extends String>) json.get("retrieve_extended_image_attrs"));
    }

    List imgFiles = (List) json.get("image_files");
    for (int i = 0; imgFiles != null && i < imgFiles.size(); i++) {
        request.imageFiles.add(new File((String) imgFiles.get(i)));
    }

    request.sourceJson = json;
    return request;
}

From source file:com.asprise.imaging.core.scan.twain.TwainUtil.java

/**
 * Deserialize JSON from String./* w w w .  j a  v  a2 s.  c  om*/
 * @param s
 * @return
 * @
 */
public static Object jsonDeserialize(String s) {
    try {
        return JSON.std.anyFrom(s);
    } catch (Throwable e) {
        throw new TwainException("Failed to parse JSON: " + s, e);
    }
}

From source file:uapi.web.http.netty.internal.NettyHttpRequest.java

private void decodeObjectBody(Class<?> objectType) {
    if (this._bodyParts.size() == 0) {
        return;//from  ww w  .j av  a  2s .c o  m
    }

    if (this._conentType != ContentType.JSON) {
        return;
    }

    try {
        this._objParam = JSON.std.beanFrom(objectType, getBodyString());
    } catch (IOException ex) {
        throw new KernelException(ex);
    }
}

From source file:com.asprise.imaging.core.scan.twain.TwainUtil.java

/**
 * Deserialize JSON from String./*  www  .j  a  v  a2  s.c o m*/
 * @param s
 * @return
 * @
 */
public static Map<String, Object> jsonDeserializeToArray(String s) {
    Map<String, Object> root = null;
    try {
        root = JSON.std.mapFrom(s);
    } catch (Throwable e) {
        throw new TwainException("Failed to parse JSON: " + s, e);
    }
    return root;
}

From source file:com.asprise.imaging.core.Imaging.java

/**
 * Performs scanning from a device and output (return, save, and/or upload).
 * @param scanRequestInJson scan request in JSON format.
 * @param sourceName the exact source name or "select" to prompt dialog selection; "default" to use default source; "current" refers to current opened source if any.
 * @param showUI set to true to use scanner UI or false to hide the UI. Set to true for maximum compatibility.
 * @param modalUI whether the scanner UI should be modal. Set to to true if you are not sure.
 * @return Scan result or null if user cancels.
 * @throws TwainException if failed.//from   w  w w .j a  v  a  2s.  c o  m
 */
public Result scan(String scanRequestInJson, String sourceName, boolean showUI, boolean modalUI) {
    ensureScanFuncsCallInTheSameThread();
    String rawResult = scanAndReturnRaw(scanRequestInJson, sourceName, showUI, modalUI);
    if (rawResult != null && rawResult.startsWith("<error:")) {
        throw new TwainException(rawResult);
    }
    try {
        Map<String, Object> root = JSON.std.mapFrom(rawResult);
        Result r = Result.createScanResult(root);
        return r;
    } catch (Throwable t) {
        throw new TwainException(rawResult, t);
    }
}

From source file:com.asprise.imaging.core.Imaging.java

/**
 * Performs image conversion and output (return, save, and/or upload).
 * @param request scan request object./*from   w w  w  .j av  a  2  s. c o  m*/
 * @return Scan result or null if user cancels.
 * @throws TwainException if failed.
 */
public Result convert(Request request) {
    String requestInJson = JsonUtils.jsonSerialize(request.toJsonObject(), true);
    String result = callNativeFunc(TwainNative.FUNC_image_output, requestInJson);
    if (result != null && result.startsWith("<error:")) {
        throw new TwainException(result);
    }
    try {
        Map<String, Object> root = JSON.std.mapFrom(result);
        return Result.createScanResult(root);
    } catch (Throwable t) {
        throw new TwainException(result, t);
    }
}

From source file:com.asprise.imaging.core.Imaging.java

/**
 * Get information about the image, e.g. bytes, width, height, etc.
 * @param imageFile Path to the image file.
 * @return Information as map//from w  w w .  j a v a  2s.  c  om
 * @throws TwainException if failed.
 */
public Map<String, Object> getImageInfo(String imageFile) {
    String result = callNativeFunc(TwainNative.FUNC_image_info, imageFile);
    try {
        Map<String, Object> root = JSON.std.mapFrom(result);
        return root;
    } catch (Throwable t) {
        throw new TwainException(result, t);
    }
}

From source file:edu.mit.lib.handbag.Controller.java

private List<Workflow> loadWorkflows() {
    // get list of agent-specific installed workflows first, then load each one.
    // It there is dispatcher web service, use it, else look in local JSON resource files
    String dispatcherUrl = appProps.get("dispatcher");
    List<Workflow> workflows = new ArrayList<>();
    try {/*  w  w  w.  j ava 2  s  .  c om*/
        List<String> workflowIds = getWorkflowIds(dispatcherUrl);
        for (String wfFile : workflowIds) {
            Workflow wf = null;
            if (dispatcherUrl != null) {
                try (InputStream in = new URL(dispatcherUrl).openConnection().getInputStream()) {
                    wf = JSON.std.beanFrom(Workflow.class, in);
                }
            } else {
                wf = JSON.std.beanFrom(Workflow.class, getClass().getResourceAsStream("/" + wfFile));
            }
            workflows.add(wf);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return workflows;
}

From source file:com.asprise.imaging.core.Imaging.java

/**
 * Performs operations on image, e.g., rotate, crop, scale, gray, etc.
 * @param inputImageFile Path to the input file.
 * @param commands Processing commands/* w  ww.j a  v a  2 s .  com*/
 * @param outputImageFile Path to the output file.
 * @return Information as map
 * @throws TwainException if failed.
 */
public Map<String, Object> processImage(String inputImageFile, String commands, String outputImageFile) {
    String result = callNativeFunc(TwainNative.FUNC_image_process, inputImageFile, commands, outputImageFile);
    try {
        Map<String, Object> root = JSON.std.mapFrom(result);
        return root;
    } catch (Throwable t) {
        throw new TwainException(result, t);
    }
}