public T deserialize(byte[] value) throws JsonParseException, JsonMappingException, IOException { if (null == value) { return null; } return JsonUtil.readValue(value, type); }
protected String serializeKey(Object key) { try { return JsonUtil.writeValueAsString(key); } catch (JsonProcessingException e) { logger.warn("Can not convert key to String.", e); } return null; }
@Override public void serialize(SnapshotTable obj, DataOutputStream out) throws IOException { String json = JsonUtil.writeValueAsIndentString(obj); out.writeUTF(json); if (infoOnly == false) obj.writeData(out); }
@Override public void serialize(T obj, DataOutputStream out) throws IOException { if (compact) JsonUtil.writeValue(out, obj); else JsonUtil.writeValueIndent(out, obj); } }
@Test public void testSerializeMap() throws Exception { Map<String, String> map = Maps.newHashMap(); map.put("key1", "value1"); map.put("key2", "value2"); String mapStr = JsonUtil.writeValueAsString(map); //System.out.println(mapStr); Map<?, ?> map2 = JsonUtil.readValue(mapStr, HashMap.class); Assert.assertEquals(map, map2); }
@Test public void testInterfaceConsistency() throws IOException { String[] attrArray = new String[] { "columnMetas", "results", "cube", "affectedRowCount", "isException", "exceptionMessage", "duration", "partial", "totalScanCount", "hitExceptionCache", "storageCacheUsed", "pushDown", "traceUrl", "totalScanBytes" }; SQLResponse sqlResponse = new SQLResponse(null, null, "learn_cube", 100, false, null, false, false); String jsonStr = JsonUtil.writeValueAsString(sqlResponse); System.out.println(jsonStr); JsonNode jnode = JsonUtil.readValueAsTree(jsonStr); assertEquals(jnode.size(), attrArray.length); for (String attr : attrArray) { Assert.assertTrue(attr + " doesn't exist", jnode.has(attr)); } } }
@Test public void testSerialize() throws Exception { CubeDesc desc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); String str = JsonUtil.writeValueAsIndentString(desc); //System.out.println(str); @SuppressWarnings("unused") CubeDesc desc2 = JsonUtil.readValue(str, CubeDesc.class); }
private void mockUpOldTableExtJson(String tableId, Map<String, String> tableExdProperties) throws IOException { String path = TableExtDesc.concatResourcePath(tableId, null); ByteArrayOutputStream os = new ByteArrayOutputStream(); JsonUtil.writeValueIndent(os, tableExdProperties); os.flush(); InputStream is = new ByteArrayInputStream(os.toByteArray()); getStore().putResource(path, is, System.currentTimeMillis()); os.close(); is.close(); } }
@Override /** * Event type does not belong to value part, it's for classification */ public byte[] getValue() { try { ByteArrayOutputStream baos = _localBaos.get(); if (baos == null) { baos = new ByteArrayOutputStream(); _localBaos.set(baos); } baos.reset(); JsonUtil.writeValue(baos, getValueRaw()); return baos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e);//in mem, should not happen } }
@Test public void foo() throws IOException { HashMap a = new HashMap<String, String>(); a.put("1", "1"); a.put("3", "3"); a.put("2", "2"); JacksonBean bean = new JacksonBean(); bean.setA("valuea"); bean.setConfiguration(a); String s = JsonUtil.writeValueAsString(bean); System.out.println(s); JacksonBean desBean = (JacksonBean) JsonUtil.readValue("{\"a\":\"valuea\",\"b\":0,\"configuration\":{\"2\":\"2\",\"3\":\"3\",\"1\":\"1\"}}", JacksonBean.class); String x2 = JsonUtil.writeValueAsString(desBean); System.out.println(x2); System.out.println(desBean); } }
@Test public void testSerialize() throws Exception { CubeDesc desc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc"); String str = JsonUtil.writeValueAsIndentString(desc); System.out.println(str); @SuppressWarnings("unused") CubeDesc desc2 = JsonUtil.readValue(str, CubeDesc.class); }
@Override public void serialize(T obj, DataOutputStream out) throws IOException { JsonUtil.writeValueIndent(out, obj); } }
@Override public void serialize(T obj, DataOutputStream out) throws IOException { if (compact) JsonUtil.writeValue(out, obj); else JsonUtil.writeValueIndent(out, obj); } }
@Override /** * Event type does not belong to value part, it's for classification */ public byte[] getValue() { try { ByteArrayOutputStream baos = _localBaos.get(); if (baos == null) { baos = new ByteArrayOutputStream(); _localBaos.set(baos); } baos.reset(); JsonUtil.writeValue(baos, getValueRaw()); return baos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e);//in mem, should not happen } }
@Override public T deserialize(DataInputStream in) throws IOException { return JsonUtil.readValue(in, clz); }
@Override public void serialize(QueryRecord record, DataOutputStream out) throws IOException { String jsonStr = JsonUtil.writeValueAsString(record); out.writeUTF(jsonStr); }
@Test public void testSerializeMap() throws Exception { Map<String, String> map = Maps.newHashMap(); map.put("key1", "value1"); map.put("key2", "value2"); String mapStr = JsonUtil.writeValueAsString(map); System.out.println(mapStr); Map<?, ?> map2 = JsonUtil.readValue(mapStr, HashMap.class); Assert.assertEquals(map, map2); }
@Override public void serialize(DictionaryInfo obj, DataOutputStream out) throws IOException { String json = JsonUtil.writeValueAsIndentString(obj); out.writeUTF(json); if (infoOnly == false) obj.getDictionaryObject().write(out); }
@Test public void testSerialization() throws IOException { IIDesc iiDesc = IIDescManager.getInstance(getTestConfig()).getIIDesc("test_kylin_ii_desc"); String str = JsonUtil.writeValueAsIndentString(iiDesc); System.out.println(str); @SuppressWarnings("unused") IIDesc desc2 = JsonUtil.readValue(str, IIDesc.class); Assert.assertEquals(iiDesc, desc2); } }
public void saveTableExd(String tableId, Map<String, String> tableExdProperties) throws IOException { if (tableId == null) { throw new IllegalArgumentException("tableId couldn't be null"); } TableDesc srcTable = srcTableMap.get(tableId); if (srcTable == null) { throw new IllegalArgumentException("Couldn't find Source Table with identifier: " + tableId); } String path = TableDesc.concatExdResourcePath(tableId); ByteArrayOutputStream os = new ByteArrayOutputStream(); JsonUtil.writeValueIndent(os, tableExdProperties); os.flush(); InputStream is = new ByteArrayInputStream(os.toByteArray()); getStore().putResource(path, is, System.currentTimeMillis()); os.close(); is.close(); srcTableExdMap.putLocal(tableId, tableExdProperties); }