ValidCharacters { public static void tagToJson(JsonGenerator gen, Tag tag) throws IOException { final String key = tag.getKey(); if (RELAXED_GROUP_KEYS.contains(key)) { gen.writeStringField(key, toValidCharsetTable(CHARS_ALLOWED_GROUPS, tag.getValue())); } else { gen.writeStringField(toValidCharset(tag.getKey()), toValidCharset(tag.getValue())); } } private  ValidCharacters(); static boolean hasInvalidCharacters(String str); static String toValidCharset(String str); static Metric toValidValue(Metric metric); static List<Metric> toValidValues(List<Metric> metrics); static void tagToJson(JsonGenerator gen, Tag tag);  }
@Test public void testTagToJson() throws Exception { Tag valid = new BasicTag("key", "value"); assertEquals(toJson(valid), "{\"key\":\"value\"}"); Tag invalidKey = new BasicTag("key~^a", "value"); assertEquals(toJson(invalidKey), "{\"key__a\":\"value\"}"); Tag invalidValue = new BasicTag("key", "value~^ 1"); assertEquals(toJson(invalidValue), "{\"key\":\"value___1\"}"); Tag relaxedValue = new BasicTag("nf.asg", "value~^ 1"); assertEquals(toJson(relaxedValue), "{\"nf.asg\":\"value~^_1\"}"); }