JsonMapper { public String toJson(Object object){ return toJson(object, true); } JsonMapper(Include include);  JsonMapper(ObjectMapper objectMapper, Include include);  JsonMapper(ObjectMapper objectMapper, Include include, boolean fieldVisibility); static SimpleFilterProvider exceptFilter(String id, String...properties); static JsonMapper defaultMapper(); static JsonMapper ignoreNull(); static JsonMapper ignoreEmpty(); static JsonMapper mapper(Include include, boolean fieldVisibility); JsonMapper prettyPrint(); JsonMapper singleQuotes(); JsonMapper allowSingleQuotes(); JsonMapper unquotedFieldNames(); JsonMapper disable(SerializationFeature features); JsonMapper disable(DeserializationFeature features); JsonMapper enableTyping(); JsonMapper addMixIns(Class<?> mixinSource, Class<?>... targets); JsonMapper defaultFiler(PropertyFilter bpf); JsonMapper filter(String id, String...properties); JsonMapper setDateFormat(String format); JsonMapper setDateFormat(String format, String timezone); String toJson(Object object); ObjectWriter writer(FilterProvider filterProvider); String toJson(Object object, boolean throwIfError); byte[] toJsonBytes(Object object); byte[] toJsonBytes(Object object, boolean throwIfError); JsonNode readTree(String content); JsonNode readTree(InputStream in); String toJsonPadding(String function, Object object); String toJsonPadding(Object object); T fromJsonWith(String json, Class<?> type, Class<?>...parameterTypes); T fromJson(final Object json, Type objType); @SuppressWarnings("unchecked") T fromJson(final Object json, Type objType, boolean parseAsStringIfError); T fromJson(final Object json, TypeReference<T> valueTypeRef); JavaType constructJavaType(Type objType); T fromJson(InputStream in, Type objType); T[] fromJsonAsArray(String json, Class<T> objClass); @SuppressWarnings("unchecked") List<T> fromJsonAsList(String json); T update(String jsonString, T object); ObjectMapper getObjectMapper(); final static String TIME_ZONE_CHINESE; static String DEFAULT_JSONP_NAME; static final JsonMapper DEFAULT_MAPPER; static final JsonMapper IGNORE_NULL; static final JsonMapper IGNORE_EMPTY; }
@Test public void testCauseMap(){ ParamMap map = new ParamMap(); map.putElement("aa", "aavalue"); map.putElement("bb", "bbvalue"); String json = JsonMapper.IGNORE_EMPTY.toJson(map); System.out.println("json: " +json); Assert.assertEquals("{\"aa\":[\"aavalue\"],\"bb\":[\"bbvalue\"]}", json); Map<String, String> map2 = new HashMap<String, String>(); map2.put("aa", "aavalue"); map2.put("bb", "bbvalue"); json = JsonMapper.IGNORE_EMPTY.toJson(map2); System.out.println("json: " +json); }
@Test public void testEnum(){ EnumVo v = new EnumVo(); v.setField("fieldValue"); v.setIntField(11); v.setType(EnumTest.FINISHED); String json = JsonMapper.IGNORE_EMPTY.toJson(v); System.out.println("json: " + json); Assert.assertEquals("{\"field\":\"fieldValue\",\"intField\":11,\"type\":\"FINISHED\"}", json);; }