@Test public void testToJson() { ObjectConverter<TestClass> c = new ObjectConverter<ObjectConverterTest.TestClass>(); TestClass t = new TestClass(); t.setI(10); t.setS("str"); String json = c.toJson(t); TestClass t1 = c.fromJson(json, TestClass.class); Assert.assertEquals(t.getI(), t1.getI()); Assert.assertEquals(t.getS(), t1.getS()); }
public String toJson(T object) { try { return mapper.writeValueAsString(object); } catch (Exception e) { logger.error("convert to json error", e); throw new MetaDataException(MetaErrCodeEnum.JSON_CONVERT_ERROR, "convert to json error", e); } }
ObjectConverter { public String toJson(T object) { try { return mapper.writeValueAsString(object); } catch (Exception e) { logger.error("convert to json error", e); throw new MetaDataException(MetaErrCodeEnum.JSON_CONVERT_ERROR, "convert to json error", e); } } }
ObjectConverter { public String toJson(T object) { try { return mapper.writeValueAsString(object); } catch (Exception e) { logger.error("convert to json error", e); throw new MetaDataException(MetaErrCodeEnum.JSON_CONVERT_ERROR, "convert to json error", e); } }  }
ObjectConverter { public String toJson(T object) { try { return mapper.writeValueAsString(object); } catch (Exception e) { logger.error("convert to json error", e); throw new MetaDataException(MetaErrCodeEnum.JSON_CONVERT_ERROR, "convert to json error", e); } }  String toJson(T object); JsonNode toJsonNode(T object); T fromJson(String json, Class<T> type); DBObject toBson(T object); T fromBson(DBObject dbObject, Class<T> type); }
ObjectConverter { public String toJson(T object) { try { return mapper.writeValueAsString(object); } catch (Exception e) { logger.error("convert to json error", e); throw new MetaDataException(MetaErrCodeEnum.JSON_CONVERT_ERROR, "convert to json error", e); } }  String toJson(T object); JsonNode toJsonNode(T object); T fromJson(String json, Class<T> type); DBObject toBson(T object); T fromBson(DBObject dbObject, Class<T> type); static final ObjectMapper mapper; }