All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.openservices.eas.predict.response.JsonResponse Maven / Gradle / Ivy

There is a newer version: 2.0.20
Show newest version
package com.aliyun.openservices.eas.predict.response;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.google.common.reflect.TypeToken;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JsonResponse {
	public static class ResponseItem {
		private String outputLabel;
		private Map outputValue;
		private Map outputMulti;

		public String getOutputLabel() {
			return outputLabel;
		}

		public void setOutputLabel(String outputLabel) {
			this.outputLabel = outputLabel;
		}

		public Map getOutputValue() {
			return outputValue;
		}

		public void setOutputValue(Map outputValue) {
			this.outputValue = outputValue;
		}

		public Map getOutputMulti() {
			return outputMulti;
		}

		public void setOutputMulti(Map outputMulti) {
			this.outputMulti = outputMulti;
		}
	}

	public void setContentValues(byte[] content) throws Exception {
		try {
			Map output = JSON.parseObject(new String(content),
					new TypeToken>(){}.getType());
			List> outputRecords = JSON.parseObject(
					output.get("outputs").toString(),
					new TypeToken>>(){}.getType());
			for (int i = 0; i< outputRecords.size(); i++) {
				ResponseItem item = new ResponseItem();
				HashMap outputRecord = outputRecords.get(i);
				item.setOutputLabel(outputRecord.get("outputLabel").toString());
				Map outputMulti = JSON.parseObject(
						outputRecord.get("outputMulti").toString(),
						new TypeToken>(){}.getType());
				item.setOutputMulti(outputMulti);
				Map outputValue = JSON.parseObject(
						outputRecord.get("outputValue").toString(),
						new TypeToken>(){}.getType());
				item.setOutputValue(outputValue);
				outputs.add(item);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private List outputs = new ArrayList<>();

	public List getOutputs() {
		return outputs;
	}

	public void setOutputs(List outputs) {
		this.outputs = outputs;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy