JsonUtils { public static JsonObject mapToJson(Map<String, ?> map) { Objects.requireNonNull(map, CANNOT_CONVERT_NULL_TO_A_JSON_OBJECT); try { return Json.instance().parse(objectMapper.writeValueAsString(map)); } catch (JsonProcessingException e) { throw new RuntimeException("Error converting map to JSON", e); } } private  JsonUtils(); static boolean jsonEquals(JsonValue a, JsonValue b); static Stream<T> stream(JsonArray array); static Stream<JsonObject> objectStream(JsonArray array); static DoubleStream numberStream(JsonArray array); static Collector<JsonValue, JsonArray, JsonArray> asArray(); static JsonArray createArray(JsonValue... values); static JsonObject createObject(Map<String, T> map,
            Function<T, JsonValue> itemToJson); static JsonObject beanToJson(Object bean); static JsonArray listToJson(List<?> list); static JsonObject mapToJson(Map<String, ?> map);  }
@Test public void simpleMapToJson() { Map<String, Object> map = new HashMap<>(); SimpleBean bean1 = new SimpleBean(); bean1.string = "bean1"; SimpleBean bean2 = new SimpleBean(); bean2.string = "bean2"; map.put("one", bean1); map.put("two", bean2); JsonObject json = JsonUtils.mapToJson(map); Assert.assertEquals("bean1", json.getObject("one").getString("string")); Assert.assertEquals("bean2", json.getObject("two").getString("string")); }