output data -> json byte[]
This commit is contained in:
snoop 2017-04-11 11:02:52 +09:00
parent 0c7ce4655c
commit c5f431116c
2 changed files with 30 additions and 6 deletions

View File

@ -1,6 +1,9 @@
package com.loafle.overflow.rpc.api;
import com.fasterxml.jackson.core.JsonEncoding;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl;
import com.loafle.overflow.rpc.crawler.Crawler;
import com.loafle.overflow.rpc.model.Input;
@ -40,8 +43,11 @@ public class RemoteImpl implements Remote {
} else {
Output out = new Output();
out.setStartDate(new Date());
Object obj = crawler.add(input.getId());
out.setEndDate(new Date());
out.setData(crawler.add(input.getId()));
out.setData(convertObjectToJsonBytes(obj));
return out;
}
@ -74,8 +80,11 @@ public class RemoteImpl implements Remote {
Output out = new Output();
out.setStartDate(new Date());
Object result = crawler.get(input.getId());
out.setEndDate(new Date());
out.setData(crawler.get(input.getId()));
out.setData(convertObjectToJsonBytes(result));
return out;
}
@ -90,9 +99,24 @@ public class RemoteImpl implements Remote {
} else {
Output out = new Output();
out.setStartDate(new Date());
Object obj = crawler.remove(input.getId());
out.setEndDate(new Date());
out.setData(crawler.remove(input.getId()));
out.setData(convertObjectToJsonBytes(obj));
return out;
}
}
private byte[] convertObjectToJsonBytes(Object object) throws Exception {
if(object == null) {
return null;
}
ObjectMapper mapper = new ObjectMapper();
String jsonInString = mapper.writeValueAsString(object);
return jsonInString.getBytes();
}
}

View File

@ -8,7 +8,7 @@ import java.util.Date;
public class Output {
private Date startDate;
private Date endDate;
private Object data;
private byte[] data;
public Date getStartDate() {
return startDate;
@ -26,11 +26,11 @@ public class Output {
this.endDate = endDate;
}
public Object getData() {
public byte[] getData() {
return data;
}
public void setData(Object data) {
public void setData(byte[] data) {
this.data = data;
}
}