DDMFormJSONSerializer implements DDMFormSerializer { @Override public DDMFormSerializerSerializeResponse serialize( DDMFormSerializerSerializeRequest ddmFormSerializerSerializeRequest) { DDMForm ddmForm = ddmFormSerializerSerializeRequest.getDDMForm(); JSONObject jsonObject = _jsonFactory.createJSONObject(); addAvailableLanguageIds(jsonObject, ddmForm.getAvailableLocales()); addDefaultLanguageId(jsonObject, ddmForm.getDefaultLocale()); addFields(jsonObject, ddmForm.getDDMFormFields()); addRules(jsonObject, ddmForm.getDDMFormRules()); addSuccessPageSettings( jsonObject, ddmForm.getDDMFormSuccessPageSettings()); if (Validator.isNotNull(ddmForm.getDefinitionSchemaVersion())) { jsonObject.put( "definitionSchemaVersion", ddmForm.getDefinitionSchemaVersion()); } DDMFormSerializerSerializeResponse.Builder builder = DDMFormSerializerSerializeResponse.Builder.newBuilder( jsonObject.toString()); return builder.build(); }  @Override DDMFormSerializerSerializeResponse serialize(
		DDMFormSerializerSerializeRequest ddmFormSerializerSerializeRequest);  }
@Test public void testDDMFormSerialization() throws Exception { String expectedJSON = read("ddm-form-json-serializer-test-data.json"); DDMForm ddmForm = createDDMForm(); ddmForm.setDDMFormRules(createDDMFormRules()); ddmForm.setDDMFormSuccessPageSettings( createDDMFormSuccessPageSettings()); String actualJSON = serialize(ddmForm); JSONAssert.assertEquals(expectedJSON, actualJSON, false); }
@Test public void testDDMFormSerializationWithSchemaVersion() throws Exception { String expectedJSON = read( "ddm-form-json-serializer-with-definition-schema-version.json"); DDMForm ddmForm = createDDMForm(); ddmForm.setDefinitionSchemaVersion("2.0"); String actualJSON = serialize(ddmForm); JSONAssert.assertEquals(expectedJSON, actualJSON, false); }