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:com.asprise.imaging.core.util.JsonUtils.java

public static Map<Object, Object> parseJson(String s) throws IOException {
    JsonParser parser = new JsonFactory().enable(JsonParser.Feature.ALLOW_COMMENTS).createParser(s);
    Map<Object, Object> json = JSON.std.mapFrom(parser);
    return json;/*from   w ww .  j  a va2 s .c  om*/
}

From source file:com.asprise.imaging.core.util.JsonUtils.java

public static String jsonSerialize(Object jsonObject, boolean pretty) {
    try {//from w ww .j  a  v  a 2 s  . c o m
        return JSON.std.with(JSON.Feature.PRETTY_PRINT_OUTPUT, pretty).with(JSON.Feature.WRITE_NULL_PROPERTIES)
                .asString(jsonObject);
    } catch (Throwable e) {
        throw new TwainException("Failed to serialize JSON", e);
    }
}

From source file:uapi.service.JsonStringCodec.java

@Override
public String decode(final Object value, final Class type) throws KernelException {
    ArgumentChecker.required(value, "value");
    ArgumentChecker.required(type, "type");
    if (type.equals(String.class) && value instanceof String) {
        return value.toString();
    }//from www  .  ja va2s .  c om
    try {
        return JSON.std.asString(value);
    } catch (Exception ex) {
        throw new KernelException(ex);
    }
}

From source file:uapi.config.internal.JsonFileParser.java

@Override
@SuppressWarnings("unchecked")
public Map<String, Object> parse(File configFile) {
    try {//w ww .  j a  va 2s  . co  m
        return extract(configFile, input -> {
            JSON.std.with(JSON.Feature.READ_ONLY);
            return JSON.std.mapFrom(input);
        });
    } catch (IOException ex) {
        this._logger.error(ex, "Parse file {} failed", configFile.getName());
    }
    return null;
}

From source file:uapi.service.JsonStringCodec.java

@Override
public Object encode(final String value, final Class type) throws KernelException {
    ArgumentChecker.required(value, "value");
    ArgumentChecker.required(type, "type");
    if (type.equals(String.class)) {
        return value;
    }/* www. j a v  a 2  s  .c om*/
    try {
        if (type.equals(Map.class)) {
            return JSON.std.mapFrom(value);
        } else if (type.equals(List.class)) {
            return JSON.std.listFrom(value);
        } else {
            return JSON.std.beanFrom(type, value);
        }
    } catch (Exception ex) {
        throw new KernelException(ex);
    }
}

From source file:org.pdfsam.ui.DefaultStageServiceTest.java

@Test
public void save() throws JSONObjectException, IOException {
    StageStatus status = new StageStatus(10, 20, 100, 200);
    victim.save(status);/*from w  w w .  j  a v  a2 s  . co m*/
    StageStatus storedStatus = JSON.std.beanFrom(StageStatus.class, Preferences.userRoot()
            .node(DefaultStageService.STAGE_PATH).get(DefaultStageService.STAGE_STATUS_KEY, ""));
    assertEquals(status, storedStatus);
}

From source file:org.pdfsam.update.DefaultUpdateService.java

public String getLatestVersion() {
    try {/*  w w w  . jav  a2 s . c om*/
        return JSON.std.mapFrom(jsonSource).getOrDefault(CURRENT_VERSION_KEY, "").toString();
    } catch (IOException e) {
        LOG.warn(DefaultI18nContext.getInstance().i18n("Unable to find the latest available version."), e);
    }
    return EMPTY;
}

From source file:org.pdfsam.module.PreferencesUsageDataStoreTest.java

@Test
public void incrementUsageFor() throws JSONObjectException, IOException {
    victim.incrementUsageFor("moduleId");
    ModuleUsage usage = JSON.std.beanFrom(ModuleUsage.class,
            Preferences.userRoot().node(PreferencesUsageDataStore.USAGE_PATH).node("moduleId")
                    .get(PreferencesUsageDataStore.MODULE_USAGE_KEY, ""));
    assertEquals(1, usage.getTotalUsed());
    assertTrue(usage.getLastSeen() != 0);
}

From source file:org.pdfsam.ui.DefaultStageService.java

public void save(StageStatus status) {
    Preferences node = Preferences.userRoot().node(STAGE_PATH);
    try {/*from  w  w w.  j av a  2s  .c o m*/
        node.put(STAGE_STATUS_KEY, JSON.std.asString(status));
        LOG.trace("Stage status saved {}", status);
    } catch (IOException e) {
        LOG.error("Unable to increment modules usage statistics", e);
    }
}

From source file:io.fineo.drill.rule.TestDrill.java

@Test
public void testReadWrite() throws Exception {
    // writer a simple json file
    Map<String, Object> json = new HashMap<>();
    json.put("a", "c");

    File tmp = folder.newFolder("drill");
    File out = new File(tmp, "test.json");
    JSON j = JSON.std;
    j.write(json, out);//from w w  w . j  av a2  s  . c om

    try (Connection conn = drill.getConnection()) {
        conn.createStatement().execute("ALTER SESSION SET `store.format`='json'");
        String select = String.format("SELECT * FROM dfs.`%s`", out.getPath());
        ResultSet results = conn.createStatement().executeQuery(select);
        assertTrue(results.next());
        assertEquals(json.get("a"), results.getString("a"));
        assertEquals(1, results.getMetaData().getColumnCount());
    }
}