=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java 2014-02-06 06:37:09 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java 2014-02-06 08:24:34 +0000 @@ -528,6 +528,11 @@ public static Map getJacksonClassMap( Class clazz ) { + return getJacksonClassMap( clazz, true ); + } + + public static Map getJacksonClassMap( Class clazz, boolean deep ) + { if ( classMapCache.containsKey( clazz ) ) { return classMapCache.get( clazz ); @@ -543,13 +548,15 @@ { JsonProperty jsonProperty = method.getAnnotation( JsonProperty.class ); - if ( StringUtils.isEmpty( jsonProperty.value() ) ) + String name = jsonProperty.value(); + + if ( StringUtils.isEmpty( name ) ) { String[] getters = new String[]{ "is", "has", "get" }; - String name = method.getName(); + name = method.getName(); for ( String getter : getters ) { @@ -559,11 +566,44 @@ } } - output.put( StringUtils.uncapitalize( name ), method ); + name = StringUtils.uncapitalize( name ); + output.put( name, method ); } else { - output.put( jsonProperty.value(), method ); + output.put( name, method ); + } + + Class returnType = method.getReturnType(); + + if ( deep && IdentifiableObject.class.isAssignableFrom( returnType ) ) + { + Map classMap = getJacksonClassMap( returnType, false ); + + for ( String key : classMap.keySet() ) + { + output.put( name + "." + key, classMap.get( key ) ); + } + } + else if ( deep && Collection.class.isAssignableFrom( returnType ) ) + { + Type type = method.getGenericReturnType(); + + if ( ParameterizedType.class.isInstance( type ) ) + { + ParameterizedType parameterizedType = (ParameterizedType) type; + Class klass = (Class) parameterizedType.getActualTypeArguments()[0]; + + if ( IdentifiableObject.class.isAssignableFrom( klass ) ) + { + Map classMap = getJacksonClassMap( klass, false ); + + for ( String key : classMap.keySet() ) + { + output.put( name + "." + key, classMap.get( key ) ); + } + } + } } } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java 2014-02-06 06:37:09 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java 2014-02-06 08:24:34 +0000 @@ -230,7 +230,7 @@ } @SuppressWarnings( "unchecked" ) - private static List> getIdentifiableObjectProperties( Object o ) + private static Object getIdentifiableObjectProperties( Object o ) { List> idPropertiesList = Lists.newArrayList(); Collection identifiableObjects; @@ -241,7 +241,7 @@ } catch ( ClassCastException ex ) { - return null; + return o; } for ( IdentifiableObject identifiableObject : identifiableObjects ) @@ -250,7 +250,12 @@ idProps.put( "id", identifiableObject.getUid() ); idProps.put( "name", identifiableObject.getDisplayName() ); - idProps.put( "code", identifiableObject.getCode() ); + + if ( identifiableObject.getCode() == null ) + { + idProps.put( "code", identifiableObject.getCode() ); + } + idProps.put( "created", identifiableObject.getCreated() ); idProps.put( "lastUpdated", identifiableObject.getLastUpdated() );