Json { @Nonnull public static String toStringJson(@Nullable final Object obj) { if (obj == null) { return "null"; } String result; try { result = STRING_MAPPER.writeValueAsString(obj); } catch (final JsonMappingException ignored) { result = "error"; } catch (final IOException e) { LOG.error("toStringJson: Cannot map {} --> JSON, {}", obj.getClass().getCanonicalName(), e.toString()); result = "error"; } return result; } private  Json(); @Nonnull static ObjectMapper getCurrentJsonObjectMapper(); @Nonnull static ObjectMapper getCurrentStringObjectMapper(); @Nonnull static String toJson(@Nonnull final Object obj); @Nullable static T fromJson(@Nonnull final String json, @Nonnull final Class<T> type); @Nonnull static String toStringJson(@Nullable final Object obj);  }
@Test public void testToStringJson() { LOG.info("testToStringJson"); final GeoRectangle a = new GeoRectangle(new GeoPoint(1.0, 2.0), new GeoPoint(3.0, 4.0)); final String x1 = Json.toStringJson(a); Assert.assertEquals( "{\"southWest\":{\"lat\":1.0,\"lon\":2.0},\"northEast\":{\"lat\":3.0,\"lon\":4.0}}", x1); Assert.assertEquals("null", Json.toStringJson(null)); }