### Question:
FilterHandler { public void serializeFilter(DataInputsType dataInputs, DataFilter filter, Geometry spatialFilter, String layerName) { if (filter != null || spatialFilter != null) { OGCFilterParameters parameters = new OGCFilterParameters(); parameters.setUserFilter(filter); parameters.setRegion(spatialFilter); parameters.setGeometryTagName("GEOM"); FilterType ogcFilter = OGCFilterGenerator.buildQuery(parameters, layerName); net.opengis.ogc._110.ObjectFactory ogcObjectFactory = new net.opengis.ogc._110.ObjectFactory(); JAXBElement<FilterType> rootFilter = ogcObjectFactory.createFilter(ogcFilter); InputType input = new InputType(); DataType data = new DataType(); ComplexDataType complexData = new ComplexDataType(); complexData.setMimeType("text/xml"); complexData.getContent().add(rootFilter); data.setComplexData(complexData); CodeType codeType = new CodeType(); codeType.setValue(StreamingConstants.LAYER_FILTER); input.setIdentifier(codeType); input.setData(data); dataInputs.getInput().add(input); } }  void serializeFilter(DataInputsType dataInputs, DataFilter filter, Geometry spatialFilter, String layerName);  }### Answer:
@Test public void testSerializeFilter() throws JAXBException, IOException { FilterHandler handler = new FilterHandler(); DataInputsType dataInputs = new DataInputsType(); ImmutableDataFilterCriteria criteria = new ImmutableDataFilterCriteria("column1", "value1", Conditional.EQ, null); ImmutableDataFilterGroup group = new ImmutableDataFilterGroup("group", Logical.AND, New.list(criteria), New.<DataFilterGroup>list(), null); ImmutableDataFilter filter = new ImmutableDataFilter("filter", "type", New.list("column1"), group, null, null); handler.serializeFilter(dataInputs, filter, null, "layer"); Execute execute = new Execute(); execute.setDataInputs(dataInputs); InputStream stream = XMLUtilities.writeXMLObjectToInputStreamSync(execute, Execute.class, FilterType.class); String xml = new StreamReader(stream).readStreamIntoString(StringUtilities.DEFAULT_CHARSET); String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns2:Execute>\n" + " <ns2:DataInputs>\n" + " <ns2:Input>\n" + " <ns1:Identifier>layerFilter</ns1:Identifier>\n" + " <ns2:Data>\n" + " <ns2:ComplexData mimeType=\"text/xml\">\n" + " <ns5:Filter>\n" + " <ns5:And>\n" + " <ns5:And>\n" + " <ns5:PropertyIsEqualTo>\n" + " <ns5:PropertyName>column1</ns5:PropertyName>\n" + " <ns5:Literal>value1</ns5:Literal>\n" + " </ns5:PropertyIsEqualTo>\n" + " </ns5:And>\n" + " </ns5:And>\n" + " </ns5:Filter>\n" + " </ns2:ComplexData>\n" + " </ns2:Data>\n" + " </ns2:Input>\n" + " </ns2:DataInputs>\n" + "</ns2:Execute>\n"; xml = xml.replace("xmlns:ns1=\"http: xml = xml.replace("xmlns:ns2=\"http: xml = xml.replace("xmlns:ns3=\"http: xml = xml.replace("xmlns:ns5=\"http: xml = xml.replace("xmlns:ns6=\"http: xml = xml.replace("xmlns:ns7=\"http: xml = xml.replace("xmlns:ns8=\"http: xml = xml.replaceAll("\\<ns2:Execute\\s+\\>", "<ns2:Execute>"); xml = xml.replaceAll("\r?\n", ""); expectedXml = expectedXml.replaceAll("\n", ""); assertEquals(expectedXml, xml); }