JsonHelper { public String objectToJson(Object object) throws IllegalStateException { ObjectMapper mapper = new ObjectMapper(); StringWriter stringWriter = new StringWriter(); try { mapper.writeValue(stringWriter, object); } catch (IOException e) { throw new IllegalStateException(e); } return stringWriter.toString(); }  T getKeyValue(JSONObject jsonObject, Object key, Class<T> classType); String objectToJson(Object object); List<T> unmarshallJsonToListOfObjects(Class<T> classType, String jsonContent); T unmarshallJsonToObject(Class<T> classType, String jsonContent);  }
@Test public void testObjectToJson() { assertEquals(String.format("\"%s\"", STRING_VALUE), jsonHelper.objectToJson(STRING_VALUE)); }
@Test public void testObjectToJsonValidateJsonIgnoreOnExpectedPartitionValues() { BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper .createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, NO_ATTRIBUTES); PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP); expectedPartitionValueDaoTestHelper .createExpectedPartitionValueEntities(partitionKeyGroupEntity, Arrays.asList(PARTITION_VALUE, PARTITION_VALUE_2, PARTITION_VALUE_3)); businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(businessObjectDefinitionEntity, FORMAT_USAGE_CODE, fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE, null), FORMAT_VERSION, FORMAT_DESCRIPTION, FORMAT_DOCUMENT_SCHEMA, FORMAT_DOCUMENT_SCHEMA_URL, LATEST_VERSION_FLAG_SET, PARTITION_KEY, partitionKeyGroupEntity, NO_ATTRIBUTES, SCHEMA_DELIMITER_COMMA, SCHEMA_COLLECTION_ITEMS_DELIMITER_COMMA, SCHEMA_MAP_KEYS_DELIMITER_HASH, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_CUSTOM_ROW_FORMAT, SCHEMA_CUSTOM_CLUSTERED_BY_VALUE, SCHEMA_NULL_VALUE_BACKSLASH_N, NO_COLUMNS, NO_PARTITION_COLUMNS); String result = jsonHelper.objectToJson(businessObjectDefinitionEntity); assertNotNull(result); assertTrue(result.contains("partitionKeyGroup")); assertFalse(result.contains("expectedPartitionValues")); assertFalse(result.contains(PARTITION_VALUE)); assertFalse(result.contains(PARTITION_VALUE_2)); assertFalse(result.contains(PARTITION_VALUE_3)); }
@Test public void testObjectToJsonValidateNoStackOverflowErrorWithCircularDependency() { BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper .createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, NO_ATTRIBUTES); BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper .createBusinessObjectFormatEntity(businessObjectDefinitionEntity, FORMAT_USAGE_CODE, fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE, null), FORMAT_VERSION, FORMAT_DESCRIPTION, FORMAT_DOCUMENT_SCHEMA, FORMAT_DOCUMENT_SCHEMA_URL, LATEST_VERSION_FLAG_SET, PARTITION_KEY, null, NO_ATTRIBUTES, SCHEMA_DELIMITER_COMMA, SCHEMA_COLLECTION_ITEMS_DELIMITER_COMMA, SCHEMA_MAP_KEYS_DELIMITER_HASH, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_CUSTOM_ROW_FORMAT, SCHEMA_CUSTOM_CLUSTERED_BY_VALUE, SCHEMA_NULL_VALUE_BACKSLASH_N, NO_COLUMNS, NO_PARTITION_COLUMNS); businessObjectFormatEntity.setBusinessObjectFormatParents(Arrays.asList(businessObjectFormatEntity)); businessObjectFormatEntity.setBusinessObjectFormatChildren(Arrays.asList(businessObjectFormatEntity)); businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity); assertNotNull(jsonHelper.objectToJson(businessObjectDefinitionEntity)); }