Microservice SDK - Retrieve MeasurementValue

Hi

I m creating a custom Microservice in Java for C8Y (10.13).
I would like my microservice to be generic and to retrieve all the measurements; without a specific type. So i call the measurementApi to retrieve the measurements from last month and end up with List of MeasurementRepresentation.

From there, I would like to retrieve the Measurement name, serie(s), unit(s) and value(s) for each MeasurementRepresentation.
For example

Memory”: {
Total Memory”: {
“unit”: “bytes”,
“value”: 167772160
}
Used Memory”: {
“unit”: “bytes”,
“value”: 1555225
}
}

We have the type MeasurementValue within our SDK so I was hoping to be able to use this type to extract the data (the Total Memory one for example). However, it does not work and I need apparently to use the type Map<?,?> which will have the unit and the value as keys. This is really not pretty and so I was wondering if there is a nicer way to retrieve the MeasurementValue from a MeasurementRepresentation object?

Below is the ugly code for your reference; which does not work since it s not an instance of MeasurementValue. (I first look for the fragment which represents the measurement (in my example the Memory fragment)

for (String fragmentName : fragments.keySet())
		{
			if (fragments.get(fragmentName) instanceof Map<?, ?>) {
				Map<?, ?> potentialMeasurementFragment = (Map<?, ?>) fragments.get(fragmentName);
				for (Object serie : potentialMeasurementFragment.keySet())
				{
					if (serie instanceof String && potentialMeasurementFragment.get(serie) instanceof MeasurementValue)
					{
						
						MeasurementValue mv = (MeasurementValue) potentialMeasurementFragment.get(serie);
						[...]
					}
				}