com.aliyun.datahub.client.impl.serializer.GetTopicMetricRequestSerializer Maven / Gradle / Ivy
The newest version!
package com.aliyun.datahub.client.impl.serializer;
import com.aliyun.datahub.client.impl.request.GetTopicMetricRequest;
import com.aliyun.datahub.client.model.MetricType;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.util.List;
public class GetTopicMetricRequestSerializer extends JsonSerializer {
@Override
public void serialize(GetTopicMetricRequest getTopicMetricRequest, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("Action", getTopicMetricRequest.getAction());
jsonGenerator.writeNumberField("StartTime", getTopicMetricRequest.getStartTime());
jsonGenerator.writeNumberField("EndTime", getTopicMetricRequest.getEndTime());
List metricTypes = getTopicMetricRequest.getMetricTypes();
if (metricTypes != null && !metricTypes.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < metricTypes.size(); ++i) {
if (i != 0) {
sb.append(",");
}
sb.append(metricTypes.get(i).getTitle());
}
jsonGenerator.writeStringField("MetricType", sb.toString());
}
jsonGenerator.writeStringField("TimeGranularity", getTopicMetricRequest.getTimeGranularity().name());
jsonGenerator.writeStringField("AggType", getTopicMetricRequest.getAggType().name());
jsonGenerator.writeEndObject();
}
}