com.aliyun.datahub.model.serialize.CreateSubscriptionRequestJsonSer Maven / Gradle / Ivy
package com.aliyun.datahub.model.serialize;
import com.aliyun.datahub.common.transport.DefaultRequest;
import com.aliyun.datahub.common.transport.HttpMethod;
import com.aliyun.datahub.common.util.JacksonParser;
import com.aliyun.datahub.exception.DatahubClientException;
import com.aliyun.datahub.model.CreateSubscriptionRequest;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
public class CreateSubscriptionRequestJsonSer implements Serializer {
@Override
public DefaultRequest serialize(CreateSubscriptionRequest request) throws DatahubClientException {
DefaultRequest req = new DefaultRequest();
req.setHttpMethod(HttpMethod.POST);
req.setResource("/projects/" + request.getProjectName() + "/topics/" + request.getTopicName() + "/subscriptions");
ObjectMapper mapper = JacksonParser.getObjectMapper();
try {
ObjectNode node = mapper.createObjectNode();
node.put("Action", "create");
node.put("Comment", request.getComment());
req.setBody(mapper.writeValueAsString(node));
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return req;
}
private CreateSubscriptionRequestJsonSer() {}
private static CreateSubscriptionRequestJsonSer instance;
public static CreateSubscriptionRequestJsonSer getInstance() {
if (instance == null) {
instance = new CreateSubscriptionRequestJsonSer();
}
return instance;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy