@Test public void testNullValueSerialization() { Map<String, String> testMap = new HashMap<String, String>(); testMap.put("key1", "val1"); testMap.put("key2", null); byte[] bytes = JSONUtils.fromObject(testMap); String result = new String(bytes); assertFalse(result.contains("null")); }
public static <T> byte[] fromObject(T value) { JSON_MAPPER.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); JSON_MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); JSON_MAPPER.getSerializationConfig().withSerializationInclusion(Include.NON_NULL); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); JSON_MAPPER.writeValue(out, value); return out.toByteArray(); } catch (Exception e) { logger.error("Cannot map POJO to JSON: ", e); throw new IllegalStateException("Cannot map POJO to JSON: " + e.getMessage()); } }
JSONUtils { public static <T> byte[] fromObject(T value) { JSON_MAPPER.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); JSON_MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); JSON_MAPPER.getSerializationConfig().withSerializationInclusion(Include.NON_NULL); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); JSON_MAPPER.writeValue(out, value); return out.toByteArray(); } catch (Exception e) { logger.error("Cannot map POJO to JSON: ", e); throw new IllegalStateException("Cannot map POJO to JSON: " + e.getMessage()); } } }
JSONUtils { public static <T> byte[] fromObject(T value) { JSON_MAPPER.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); JSON_MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); JSON_MAPPER.getSerializationConfig().withSerializationInclusion(Include.NON_NULL); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); JSON_MAPPER.writeValue(out, value); return out.toByteArray(); } catch (Exception e) { logger.error("Cannot map POJO to JSON: ", e); throw new IllegalStateException("Cannot map POJO to JSON: " + e.getMessage()); } }  }
JSONUtils { public static <T> byte[] fromObject(T value) { JSON_MAPPER.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); JSON_MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); JSON_MAPPER.getSerializationConfig().withSerializationInclusion(Include.NON_NULL); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); JSON_MAPPER.writeValue(out, value); return out.toByteArray(); } catch (Exception e) { logger.error("Cannot map POJO to JSON: ", e); throw new IllegalStateException("Cannot map POJO to JSON: " + e.getMessage()); } }  static T toObject(byte[] value, T ref); static List<UUID> toUUIDList(String value); static byte[] fromObject(T value); }
JSONUtils { public static <T> byte[] fromObject(T value) { JSON_MAPPER.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); JSON_MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); JSON_MAPPER.getSerializationConfig().withSerializationInclusion(Include.NON_NULL); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); JSON_MAPPER.writeValue(out, value); return out.toByteArray(); } catch (Exception e) { logger.error("Cannot map POJO to JSON: ", e); throw new IllegalStateException("Cannot map POJO to JSON: " + e.getMessage()); } }  static T toObject(byte[] value, T ref); static List<UUID> toUUIDList(String value); static byte[] fromObject(T value);  }