summaryrefslogtreecommitdiffstats
path: root/dcaedt_be/src/main/java/org/onap/sdc/dcae/ves/VesJsonDeserializer.java
blob: f5cfd2a246f6accc596043f9edc0e7ea318d88f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package org.onap.sdc.dcae.ves;

import com.google.gson.*;

import java.lang.reflect.Type;

// json 'items' value can be either a single object or an array. customized POJO will always be an array
public class VesJsonDeserializer implements JsonDeserializer<VesDataItemsDefinition> {
	@Override
	public VesDataItemsDefinition deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {

		if(json instanceof JsonArray){
			 return new Gson().fromJson(json, VesDataItemsDefinition.class);
		}

		VesDataItemsDefinition items = new VesDataItemsDefinition();
		items.add(new Gson().fromJson(json, VesDataTypeDefinition.class));
		return items;
	}
}