Rule implements JsonObjectConvertible { @Override public JsonObject toJson() { return JavaxJson.key(keys().type(), getType().name()).key(keys().pattern(), getPattern().pattern()).get(); } Rule(final RuleType type, final Pattern pattern); @NotNull static JsonKeys keys(); RuleType getType(); Pattern getPattern(); boolean isInclude(); boolean isExclude(); boolean isAllow(); boolean isDeny(); boolean matches(String value); @Override JsonObject toJson(); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode();  }
@Test public void testToJson() { final Rule allowsDigits = new Rule(RuleType.ALLOW, Pattern.compile("[0-9]*")); assertEquals("expect json", key(Rule.keys().type(), "ALLOW") .key(Rule.keys().pattern(), "[0-9]*").get(), allowsDigits.toJson()); }