List of usage examples for com.fasterxml.jackson.jr.ob JSON std
JSON std
To view the source code for com.fasterxml.jackson.jr.ob JSON std.
Click Source Link
From source file:org.pdfsam.ui.JsonWorkspaceService.java
public void saveWorkspace(Map<String, Map<String, String>> data, File destination) { requireNotNull(destination, "Destination file cannot be null"); LOG.debug(DefaultI18nContext.getInstance().i18n("Saving workspace data to {0}", destination.getAbsolutePath())); try {/*w ww .j a va2 s. c om*/ JSON.std.with(JSON.Feature.PRETTY_PRINT_OUTPUT).without(JSON.Feature.WRITE_NULL_PROPERTIES).write(data, destination); LOG.info(DefaultI18nContext.getInstance().i18n("Workspace saved")); } catch (Exception e) { // make it unchecked throw new RuntimeException(e); } }
From source file:org.pdfsam.ui.StatefullPreferencesStageServiceTest.java
@Test public void save() throws JSONObjectException, IOException { StageStatus status = new StageStatus(10, 20, 100, 200); victim.save(status);//from w ww. j ava 2 s. c o m StageStatus storedStatus = JSON.std.beanFrom(StageStatus.class, Preferences.userRoot().node(StatefullPreferencesStageService.STAGE_PATH) .get(StatefullPreferencesStageService.STAGE_STATUS_KEY, "")); assertEquals(status, storedStatus); }
From source file:org.pdfsam.news.DefaultNewsService.java
public List<NewsData> getLatestNews() { try {/*from w w w. j a v a2 s . com*/ return JSON.std.with(Feature.READ_ONLY, true).listOfFrom(NewsData.class, new URL(pdfsam.property(ConfigurableProperty.NEWS_URL))); } catch (IOException e) { LOG.warn(DefaultI18nContext.getInstance().i18n("Unable to retrieve latest news"), e); } return Collections.emptyList(); }
From source file:com.github.gilbertotorrezan.viacep.se.ViaCEPClient.java
/** * Construtor padro. */ public ViaCEPClient() { service = JSON.std; }
From source file:org.pdfsam.ui.DefaultStageService.java
public StageStatus getLatestStatus() { Preferences node = Preferences.userRoot().node(STAGE_PATH); try {/*from w w w. ja v a 2 s .com*/ String statusString = node.get(STAGE_STATUS_KEY, ""); if (isNotBlank(statusString)) { return JSON.std.beanFrom(StageStatus.class, statusString); } } catch (IOException e) { LOG.error("Unable to get latest stage status", e); } return StageStatus.NULL; }
From source file:org.pdfsam.module.PreferencesUsageDataStoreTest.java
@Test public void multipleIncrementUsageFor() 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, "")); victim.flush();/*from w w w . ja va 2s . co m*/ victim.incrementUsageFor("moduleId"); ModuleUsage usage2 = JSON.std.beanFrom(ModuleUsage.class, Preferences.userRoot().node(PreferencesUsageDataStore.USAGE_PATH).node("moduleId") .get(PreferencesUsageDataStore.MODULE_USAGE_KEY, "")); assertEquals(2, usage2.getTotalUsed()); assertTrue(usage.getLastSeen() != usage2.getLastSeen()); }
From source file:org.pdfsam.module.PreferencesUsageDataStore.java
public void incrementUsageFor(String moduleId) { Preferences node = Preferences.userRoot().node(USAGE_PATH).node(moduleId); String json = node.get(MODULE_USAGE_KEY, ""); try {/*from w ww.j a va2 s . c om*/ if (isNotBlank(json)) { node.put(MODULE_USAGE_KEY, JSON.std.asString(JSON.std.beanFrom(ModuleUsage.class, json).inc())); } else { node.put(MODULE_USAGE_KEY, JSON.std.asString(ModuleUsage.fistUsage(moduleId))); } LOG.trace("Usage incremented for module {}", moduleId); } catch (IOException e) { LOG.error("Unable to increment modules usage statistics", e); } finally { incrementTotalUsage(); } }
From source file:org.pdfsam.ui.JsonWorkspaceService.java
@SuppressWarnings("unchecked") public Map<String, Map<String, String>> loadWorkspace(File workspace) { requireNotNull(workspace, "Workspace file cannot be null"); Map<String, Map<String, String>> data = Collections.emptyMap(); try (FileInputStream stream = new FileInputStream(workspace)) { data = (Map) JSON.std.mapFrom(stream); } catch (Exception e) { // make it unchecked throw new RuntimeException(e); }//from ww w. j ava2 s . c o m return data; }
From source file:ws.util.AbstractJSONCoder.java
@Override public T decode(String json) throws DecodeException { // logger.log(Level.INFO, new StringBuilder() // .append("[coder] decoding.. ") // .append(json) // .toString()); try {//from w ww. j av a 2 s . c o m // TODO: ?????Jacson Jr????Jr?????? T pojo = JSON.std.beanFrom(type, json); // logger.log(Level.INFO, new StringBuilder() // .append("[coder] done ") // .append(message) // .toString()); return pojo; } catch (IOException e) { logger.log(Level.SEVERE, e.toString()); throw new DecodeException(json, e.getMessage()); } }
From source file:org.pdfsam.module.PreferencesUsageDataStore.java
public List<ModuleUsage> getUsages() { Preferences prefs = Preferences.userRoot().node(USAGE_PATH); List<ModuleUsage> retList = new ArrayList<>(); try {/*from w w w.j a va 2s. c o m*/ List<String> jsons = Arrays.stream(prefs.childrenNames()).parallel().map(name -> prefs.node(name)) .map(node -> node.get(MODULE_USAGE_KEY, "")).filter(json -> isNotBlank(json)).collect(toList()); for (String json : jsons) { retList.add(JSON.std.beanFrom(ModuleUsage.class, json)); } } catch (BackingStoreException | IOException e) { LOG.error("Unable to get modules usage statistics", e); } return retList; }