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:edu.mit.lib.handbag.Controller.java

private List<String> getWorkflowIds(String dispatcherUrl) throws IOException {
    List<String> wfIdList = null;
    if (dispatcherUrl == null) {
        wfIdList = JSON.std.listOfFrom(String.class, getClass().getResourceAsStream("/" + agent + ".json"));
    } else {/* w w  w.  j  a  v a2  s .c om*/
        try (InputStream in = new URL(dispatcherUrl).openConnection().getInputStream()) {
            wfIdList = JSON.std.listOfFrom(String.class, in);
        }
    }
    return wfIdList;
}

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

/**
 *
 * @param functionName//from   w ww. j  ava  2 s . co m
 * @param args Must be of type: String, Integer or Boolean;
 * @return
 * @throws RuntimeException if failed to form request in JSON format.
 */
public static String callNativeFunc(String functionName, Object... args) {
    String jsonRequest = null;
    try {
        ArrayComposer<ObjectComposer<JSONComposer<String>>> argArray = JSON.std.composeString().startObject()
                .put("function", functionName).startArrayField("args");
        for (int i = 0; args != null && i < args.length; i++) {
            Object arg = args[i];
            if (arg instanceof String) {
                argArray = argArray.add((String) arg);
            } else if (arg instanceof Integer) {
                argArray = argArray.add(((Number) arg).intValue());
            } else if (arg instanceof Long) {
                argArray = argArray.add(((Number) arg).longValue());
            } else if (arg instanceof Boolean) {
                argArray = argArray.add(((Boolean) arg).booleanValue());
            } else if (arg == null) {
                argArray = argArray.addNull();
            } else {
                throw new IllegalArgumentException(
                        "Unsupported arg type: " + arg.getClass().getName() + "; object: " + arg);
            }
        }
        jsonRequest = argArray.end().end().finish();
    } catch (Throwable e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new RuntimeException(e);
        }
    }

    if (jsonRequest == null || jsonRequest.length() == 0) {
        throw new IllegalArgumentException("Invalid requst: " + jsonRequest);
    }

    // System.out.println(jsonRequest);
    String result = TwainNative.invokeFunc(jsonRequest);
    return result;
}

From source file:org.apache.marmotta.ldpath.ldquery.LDQuery.java

public static void main(String[] args) {
    Options options = buildOptions();//from  www .  j a  v a 2 s  . c o  m

    CommandLineParser parser = new PosixParser();
    try {
        CommandLine cmd = parser.parse(options, args);

        Level logLevel = Level.WARN;

        if (cmd.hasOption("loglevel")) {
            String logLevelName = cmd.getOptionValue("loglevel");
            if ("DEBUG".equals(logLevelName.toUpperCase())) {
                logLevel = Level.DEBUG;
            } else if ("INFO".equals(logLevelName.toUpperCase())) {
                logLevel = Level.INFO;
            } else if ("WARN".equals(logLevelName.toUpperCase())) {
                logLevel = Level.WARN;
            } else if ("ERROR".equals(logLevelName.toUpperCase())) {
                logLevel = Level.ERROR;
            } else {
                log.error("unsupported log level: {}", logLevelName);
            }
        }

        if (logLevel != null) {
            for (String logname : new String[] { "at", "org", "net", "com" }) {

                ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory
                        .getLogger(logname);
                logger.setLevel(logLevel);
            }
        }

        File tmpDir = null;
        LDCacheBackend backend = new LDCacheBackend();

        Resource context = null;
        if (cmd.hasOption("context")) {
            context = backend.createURI(cmd.getOptionValue("context"));
        }

        if (backend != null && context != null) {
            LDPath<Value> ldpath = new LDPath<Value>(backend);

            if (cmd.hasOption("path")) {
                String path = cmd.getOptionValue("path");

                for (Value v : ldpath.pathQuery(context, path, null)) {
                    System.out.println(v.stringValue());
                }
            } else if (cmd.hasOption("program")) {
                File file = new File(cmd.getOptionValue("program"));

                Map<String, Collection<?>> result = ldpath.programQuery(context, new FileReader(file));

                if (cmd.hasOption("format")) {
                    final String format = cmd.getOptionValue("format");
                    if (format.equals("json")) {
                        // Jackson.jr closes the output stream.
                        final ProxyOutputStream proxyOutputStream = new ProxyOutputStream(System.out) {
                            @Override
                            public void close() throws IOException {
                                flush();
                            }
                        };
                        JSON.std.write(result, proxyOutputStream);
                        System.out.println("");
                    } else {
                        System.err.println("Unknown format: " + format);
                        System.exit(1);
                    }
                } else {
                    for (String field : result.keySet()) {
                        StringBuilder line = new StringBuilder();
                        line.append(field);
                        line.append(" = ");
                        line.append("{");
                        for (Iterator<?> it = result.get(field).iterator(); it.hasNext();) {
                            line.append(it.next().toString());
                            if (it.hasNext()) {
                                line.append(", ");
                            }
                        }
                        line.append("}");
                        System.out.println(line);

                    }
                }
            }
        }

        if (tmpDir != null) {
            FileUtils.deleteDirectory(tmpDir);
        }

    } catch (ParseException e) {
        System.err.println("invalid arguments");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("LDQuery", options, true);
    } catch (LDPathParseException e) {
        System.err.println("path or program could not be parsed");
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        System.err.println("file or program could not be found");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("LDQuery", options, true);
    } catch (IOException e) {
        System.err.println("could not access cache data directory");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("LDQuery", options, true);
    }

}