Search in sources :

Example 1 with JsonAnnotationManager

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\""));
}
Also used : JsonAnnotationManager(jodd.json.meta.JsonAnnotationManager) Test(org.junit.Test)

Aggregations

JsonAnnotationManager (jodd.json.meta.JsonAnnotationManager)1 Test (org.junit.Test)1