JsonFilterService { public String convertJsonToJpql(String jsonCriteria, ResultSetMetaData resultSetMetaData) throws SQLException { Map<String, Object> jsonCriteriaMap = new Gson().fromJson(jsonCriteria, new TypeToken<HashMap<String, Object>>() { }.getType()); String conditionString = "()"; if (jsonCriteriaMap != null && jsonCriteriaMap.size() > 0) { List<Object> queryParameters = new ArrayList<>(); conditionString = convertJsonToJpqlRecursive(jsonCriteriaMap, queryParameters, getColumnTypeMapping(resultSetMetaData)); } return !"()".equals(conditionString) ? conditionString : "1=1"; }  String convertJsonToJpql(String jsonCriteria, ResultSetMetaData resultSetMetaData);  }
@Ignore @Test public void convertJsonToSqlTest() throws SQLException { String jsonCriteria = "{\n" + " \"group\": {\n" + " \"operator\": \"AND\",\n" + " \"rules\": [\n" + " {\n" + " \"condition\": \"=\",\n" + " \"field\": \"REVENUE_GROSS\",\n" + " \"data\": \"23\",\n" + " \"$$hashKey\": \"object:434\"\n" + " },\n" + " {\n" + " \"condition\": \"=\",\n" + " \"field\": \"ID\",\n" + " \"data\": \"4\",\n" + " \"$$hashKey\": \"object:454\"\n" + " },\n" + " {\n" + " \"group\": {\n" + " \"operator\": \"AND\",\n" + " \"rules\": [\n" + " {\n" + " \"condition\": \"=\",\n" + " \"field\": \"REVENUE_NET\",\n" + " \"data\": \"22\",\n" + " \"$$hashKey\": \"object:476\"\n" + " },\n" + " {\n" + " \"condition\": \"=\",\n" + " \"field\": \"SALES_DAY\",\n" + " \"data\": \"2016-10-02T232\",\n" + " \"$$hashKey\": \"object:476\"\n" + " }\n" + " ]\n" + " },\n" + " \"$$hashKey\": \"object:463\"\n" + " }\n" + " ]\n" + " }\n" + "}"; when(resultSetMetaData.getColumnCount()).thenReturn(new Integer(3)); when(resultSetMetaData.getColumnName(0)).thenReturn("REVENUE_GROSS"); when(resultSetMetaData.getColumnName(1)).thenReturn("ID"); when(resultSetMetaData.getColumnName(2)).thenReturn("REVENUE_NET"); when(resultSetMetaData.getColumnName(3)).thenReturn("SALES_DAY"); when(resultSetMetaData.getColumnTypeName(0)).thenReturn("DOUBLE"); when(resultSetMetaData.getColumnTypeName(1)).thenReturn("BIGINT"); when(resultSetMetaData.getColumnTypeName(2)).thenReturn("DOUBLE"); when(resultSetMetaData.getColumnTypeName(3)).thenReturn("DATE"); String manualyConvertedCriteria = "(REVENUE_GROSS = 23 AND ID = 4 AND (REVENUE_NET = 22 AND SALES_DAY = '2016-10-02'))"; String convertedCriteria = jsonFilterService.convertJsonToJpql(jsonCriteria, resultSetMetaData); assertEquals(manualyConvertedCriteria, convertedCriteria); }