.addDeserializer( QueryFilter5.class, new QueryFilter5Deserializer() );
mapper.registerModule(testModule);
// Verifying that we can pass in a custom Mapper and create a new JsonUtil
JsonUtil jsonUtil = JsonUtils.customJsonUtil( mapper );
String testFixture = "/jsonUtils/testdomain/five/queryFilter-realAndLogical5.json";
// TEST JsonUtil and our deserialization logic
QueryFilter5 queryFilter = jsonUtil.classpathToType( testFixture, new TypeReference<QueryFilter5>() {} );
// Make sure the hydrated QFilter looks right
AssertJUnit.assertTrue( queryFilter instanceof LogicalFilter5);
LogicalFilter5 andFilter = (LogicalFilter5) queryFilter;
AssertJUnit.assertEquals( Operator.AND, andFilter.getOperator() );
AssertJUnit.assertNotNull(andFilter.getValues());
AssertJUnit.assertEquals(3, andFilter.getValues().size());
// Make sure one of the top level RealFilters looks right
QueryFilter5 productIdFilter = andFilter.getValues().get(1);
AssertJUnit.assertTrue( productIdFilter instanceof StringRealFilter5);
StringRealFilter5 stringRealProductIdFilter = (StringRealFilter5) productIdFilter;
AssertJUnit.assertEquals( Field.PRODUCTID, stringRealProductIdFilter.getField() );
AssertJUnit.assertEquals( Operator.EQ, stringRealProductIdFilter.getOperator() );
AssertJUnit.assertEquals( "Acme-1234", stringRealProductIdFilter.getValues().get(0) );
// Make sure the nested OR looks right
QueryFilter5 orFilter = andFilter.getValues().get(2);
AssertJUnit.assertTrue( orFilter instanceof LogicalFilter5 );
LogicalFilter5 realOrFilter = (LogicalFilter5) orFilter;
AssertJUnit.assertEquals( Operator.OR, realOrFilter.getOperator() );
AssertJUnit.assertEquals( 2, realOrFilter.getValues().size() );
// Make sure nested AND looks right
QueryFilter5 nestedAndFilter = realOrFilter.getValues().get(1);
AssertJUnit.assertTrue( nestedAndFilter instanceof LogicalFilter5 );
AssertJUnit.assertEquals( Operator.AND, nestedAndFilter.getOperator() );
AssertJUnit.assertEquals( 3, nestedAndFilter.getValues().size() );
// SERIALIZE TO STRING to test serialization logic
String unitTestString = jsonUtil.toJsonString( queryFilter );
// LOAD and Diffy the plain vanilla JSON versions of the documents
Map<String, Object> actual = JsonUtils.jsonToMap( unitTestString );
Map<String, Object> expected = JsonUtils.classpathToMap( testFixture );