use of jodd.json.meta.JsonAnnotationManager in project jodd by oblac.
the class JsonSerializerTest method testStrictMode.
@Test
public void testStrictMode() {
Cook cook = new Cook();
JsonAnnotationManager jam = JoddJson.annotationManager;
JsonAnnotationManager.TypeData typeData = jam.lookupTypeData(Cook.class);
assertEquals(1, typeData.rules.totalIncludeRules());
assertEquals(1, typeData.rules.totalExcludeRules());
assertEquals("ccc", typeData.rules.getRule(0));
assertEquals("bbb", typeData.rules.getRule(1));
JsonSerializer jsonSerializer = new JsonSerializer();
String json = jsonSerializer.serialize(cook);
assertTrue(json.contains("\"aaa\""));
assertFalse(json.contains("\"bbb\""));
assertTrue(json.contains("\"ccc\""));
// now, strict = true, serialize only annotated properties!
MasterCook masterCook = new MasterCook();
typeData = jam.lookupTypeData(MasterCook.class);
assertEquals(1, typeData.rules.totalIncludeRules());
assertEquals(1, typeData.rules.totalExcludeRules());
assertEquals("ccc", typeData.rules.getRule(0));
assertEquals("bbb", typeData.rules.getRule(1));
json = jsonSerializer.serialize(masterCook);
assertFalse(json.contains("\"aaa\""));
assertFalse(json.contains("\"bbb\""));
assertTrue(json.contains("\"ccc\""));
}
Aggregations