Class JsonUtils


  • public class JsonUtils
    extends Object
    Contains utility methods used in this module.
    Author:
    mtaal
    • Constructor Detail

      • JsonUtils

        public JsonUtils()
    • Method Detail

      • getIdentifierSet

        public static List<Property> getIdentifierSet​(Property property)
        A utility method which retrieves the properties used for identifying an entity and its first level references. Takes into accoun the different scenarios implemented in the IdentifierProvider.getIdentifier(Object) method. Is used by distinct queries to get the smallest possible select clauses.
      • createDateFormat

        public static SimpleDateFormat createDateFormat()
        Returns:
        a new instance of the SimpleDateFormat using a format of yyyy-MM-dd (xml schema date format). The date format has lenient set to true.
      • createTimeFormat

        public static SimpleDateFormat createTimeFormat()
        Returns:
        a new instance of the SimpleDateFormat using a format of HH:MM:SS+0000. The date format has lenient set to true.
      • createTimeFormatWithoutGMTOffset

        public static SimpleDateFormat createTimeFormatWithoutGMTOffset()
        Returns:
        a new instance of the SimpleDateFormat using a format of HH:MM:SS. The date format has lenient set to true.
      • createJSTimeFormat

        public static SimpleDateFormat createJSTimeFormat()
        Returns:
        a new instance of the SimpleDateFormat using a format of yyyy-MM-dd'T'HH:mm:ss (see http://www.w3.org/TR/xmlschema-2/#dateTime). The date format has lenient set to true.
      • createDateTimeFormat

        public static SimpleDateFormat createDateTimeFormat()
        Note the formatted date string must be repaired in the timezone to follow the XSD format, see: convertToCorrectXSDFormat(String).
        Returns:
        a new instance of the SimpleDateFormat using a format of yyyy-MM-dd'T'HH:mm:ss (xml schema date time format). The date format has lenient set to true.
      • convertToCorrectXSDFormat

        public static String convertToCorrectXSDFormat​(String dateValue)
        Adds a colon in the timezone part of the formatted date, see here: http://weblogs.java.net/blog/felipegaucho/archive/2009/12/06/jaxb-customization-xsddatetime
        Parameters:
        dateValue - the date value without a :, for example 2009-12-06T15:59:34+0100
        Returns:
        a colon added in the timezone part: 2009-12-06T15:59:34+01:00
      • convertExceptionToJson

        public static String convertExceptionToJson​(Throwable throwable)
        Converts an exception to its json represention. Uses the Smartclient format for the json string, see here: RestDataSource
        Parameters:
        throwable - the exception to convert to json
        Returns:
        the resulting json string
      • isQueryTimeout

        public static boolean isQueryTimeout​(Throwable localThrowable)
      • getEmptyResult

        public static String getEmptyResult()
        Returns an empty result for a fetch call
        Returns:
        the JSON representation of an empty result
      • getPropertiesOnPath

        public static List<Property> getPropertiesOnPath​(Entity entity,
                                                         String propertyPath)
        Determines the list of properties based on the property path (for example bankAccount.bank.name).
        Parameters:
        entity - the entity to start from, the first property in the property path is a property of this entity
        propertyPath - the property path, i.e. property names separated by dots
        Returns:
        the list of properties determined from the property path
      • buildCriteria

        public static org.codehaus.jettison.json.JSONObject buildCriteria​(Map<String,​String> parameters)
      • isValueEmpty

        public static boolean isValueEmpty​(String value)
        Returns whether a JSON value is empty. The following values are considered as empty:
        • An empty string
        • null
        • "null" literal
        • "undefined" literal