Operators { private static void writeFieldExistsCheckCondition( final QueryStatement query, final QueryWriterResolver resolver, final FieldPath contextFieldPath, final Object queryParameter ) throws QueryBuildException { if (contextFieldPath == null) { throw new QueryBuildException("Field check conditions not allowed outside of field context."); } try { String isNullStr = String.valueOf(queryParameter); if (!(isNullStr.equalsIgnoreCase("true") || isNullStr.equalsIgnoreCase("false"))) { throw new QueryBuildException("Parameter for existence checking should represent boolean value."); } Boolean isNull = Boolean.parseBoolean(isNullStr); String condition = isNull ? "(%s) is null" : "(%s) is not null"; query.getBodyWriter().write(String.format(condition, contextFieldPath.toSQL())); } catch (IOException e) { throw new QueryBuildException("Query search conditions write failed because of exception.", e); } } private  Operators(); static void addAll(final PostgresQueryWriterResolver resolver);  }
@Test public void writeFieldExistsCheckConditionTest() throws Exception { FieldPath fieldPath = PostgresFieldPath.fromString("isNull"); QueryStatement queryStatementIsNull = new QueryStatement(); resolver .resolve("$isNull") .write(queryStatementIsNull, resolver, fieldPath, "true"); assertEquals(queryStatementIsNull.getBodyWriter().toString().trim(), "(document#>'{isNull}') is null"); QueryStatement queryStatementIsNotNull = new QueryStatement(); resolver .resolve("$isNull") .write(queryStatementIsNotNull, resolver, fieldPath, "false"); assertEquals(queryStatementIsNotNull.getBodyWriter().toString().trim(), "(document#>'{isNull}') is not null"); }