本文整理汇总了Java中org.codehaus.jackson.type.TypeReference类的典型用法代码示例。如果您正苦于以下问题:Java TypeReference类的具体用法?Java TypeReference怎么用?Java TypeReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeReference类属于org.codehaus.jackson.type包,在下文中一共展示了TypeReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSerializeThenDeSerialize
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
@Test
public void testSerializeThenDeSerialize() throws Exception {
DeviceTagMap tagMap = new DeviceTagMap();
tagMap.addTag("device1", "tag1");
tagMap.addTag("device1", "tag2");
tagMap.addTag("device1", "tag3");
tagMap.addTag("device1", "tag4");
tagMap.addTag("device2", "tag1");
tagMap.addTag("device2", "tag2");
tagMap.addTag("device2", "tag3");
tagMap.addTag("device2", "tag4");
String marshalledString = toJsonString(tagMap.getTagInfoList());
LOGGER.trace("testSerializeThenSerialize : marshalledString=\n{}", JsonWriter.formatJson(marshalledString));
Object obj = fromJson(marshalledString, new TypeReference<List<DeviceTagInfo>>(){});
LOGGER.trace("testSerializeThenSerialize : unmarshalled object={}", obj);
List<DeviceTagInfo> unmarshalledTags = (List<DeviceTagInfo>) obj;
assertEquals(tagMap.getTagInfoList(), unmarshalledTags);
}
示例2: getApplications
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
public static List<Application> getApplications( String response )
{
List<Application> applications = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
try
{
applications = mapper.readValue( response, new TypeReference<List<Application>>()
{
} );
}
catch ( IOException e )
{
e.printStackTrace();
}
return applications;
}
示例3: getMessage
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
public static List<Message> getMessage( String response )
{
ObjectMapper mapper = new ObjectMapper();
List<Message> messages = null;
try
{
messages = mapper.readValue( response, new TypeReference<List<Message>>()
{
} );
}
catch ( IOException e )
{
e.printStackTrace();
}
return messages;
}
示例4: addNewFact
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
private boolean addNewFact(){
boolean succeeded = false;
try{
String factStr = addFactArea.getText();
Map<String, List<String>> newFact = KRFUtil.objectMapper.readValue(factStr, new TypeReference<Map<String, List<String>>>() {});
if(!isValidFact(newFact)){
throw new Exception("Invalid Format Specified For Fact!");
}
inputCaseBase.getInputCaseBase().add(newFact);
succeeded = true;
message.setText("New Fact added successfully");
}catch(Exception e){
message.setText("Error adding fact {} " + e.getMessage());
}
return succeeded;
}
开发者ID:intelligent-decision-support-systems,项目名称:knowledge-based-reasoning-framework,代码行数:18,代码来源:ReasonerGui.java
示例5: prepare
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
@Override
public void prepare(Map stormConf, TopologyContext context) {
mapper = new ObjectMapper();
this.configParams = (JSONObject) new JSONObject(this.config).get("params");
try {
this.configMap = mapper.readValue(this.config,new TypeReference<Map<String, Object>>() {});
mapParams = (Map<String,Object>) configMap.get("params");
} catch (IOException e) {
e.printStackTrace();
}
field = getParam("field1", true);
operator = getParam("operator", true);
field2 = getParam("field2", true);
entity = getParam("entity");
}
示例6: prepare
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
@Override
public void prepare(Map stormConf, TopologyContext context) {
mapper = new ObjectMapper();
this.configParams = (JSONObject) new JSONObject(this.config).get("params");
try {
this.configMap = mapper.readValue(this.config,new TypeReference<Map<String, Object>>() {});
mapParams = (Map<String,Object>) configMap.get("params");
} catch (IOException e) {
e.printStackTrace();
}
field = getParam("field", true);
operator = (String) getParam("operator", true);
value = (String) getParam("value", true);
entity = (String) getParam("value");
if (operator.equals("RegexExpression")) {
pattern = Pattern.compile(value, Pattern.DOTALL);
}
}
示例7: execute
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
@Override
public final void execute(Tuple input, BasicOutputCollector collector) {
_collector = collector;
if (isTickTuple(input)) {
tickTupleCase();
} else {
try {
this.rawJson = input.getStringByField("map");
this.json = mapper.readValue(input.getStringByField("map"),new TypeReference<Map<String, Object>>() {});
this.userexecute();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例8: execute
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
@Override
public final void execute(Tuple input, BasicOutputCollector collector) {
_collector = collector;
if (isTickTuple(input)) {
tickTupleCase();
} else {
try {
this.rawJson = input.getStringByField("map");
this.json = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {});
this.userexecute();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例9: parse
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
public static <T> BaseResult<T> parse(String responseStr, Class<T> type) {
System.out.println(responseStr);
BaseResult<T> result = new BaseResult<T>();
try {
BaseResult br = mapper.readValue(responseStr, new TypeReference<BaseResult<T>>() {});
if (br.isSuccess()) {
result.setData(mapToObject(br.getData(), type));
}
else {
result.setCode(br.getCode());
result.setMsg(br.getMsg());
}
return result;
} catch (Exception ex) {
System.err.println("Failed to Parse " + responseStr + " : " + ex.getMessage());
result.setCode(-1);
result.setMsg("response parse error");
result.setData(null);
}
return result;
}
示例10: readList
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
/**
* Reads a collection of FileTrackingStatus.<br/>
* If plain text is a list of line separated plain text.<br/>
* If json this should be a json array.<br/>
*
* @param format
* @param reader
* @return
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
*/
@SuppressWarnings("unchecked")
public Collection<FileTrackingStatus> readList(FORMAT format, Reader reader)
throws JsonParseException, JsonMappingException, IOException {
Collection<FileTrackingStatus> coll = null;
if (format.equals(FORMAT.JSON)) {
coll = (Collection<FileTrackingStatus>) mapper.readValue(reader,
new TypeReference<Collection<FileTrackingStatus>>() { });
} else {
BufferedReader buff = new BufferedReader(reader);
coll = new ArrayList<FileTrackingStatus>();
String line = null;
while ((line = buff.readLine()) != null) {
coll.add(read(FORMAT.TXT, line));
}
}
return coll;
}
示例11: createDocument
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
public static SolrInputDocument createDocument(String dataStr)
throws JsonParseException, JsonMappingException, IOException {
Map<String, Object> dataMap =
new ObjectMapper().readValue(dataStr, new TypeReference<HashMap<String, Object>>() {
});
SolrInputDocument document = new SolrInputDocument();
for (Iterator<String> i = dataMap.keySet().iterator(); i.hasNext();) {
String fieldName = i.next();
Object fieldValue = dataMap.get(fieldName);
document.addField(fieldName, fieldValue);
}
return document;
}
示例12: testExecute
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
@Test
public void testExecute() throws SolrServerException, IOException {
String solrUrl = cluster.getJettySolrRunners().get(0).getBaseUrl() + "/" + COLLECTION;
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put("solr_url", solrUrl);
attrs.put("unique_id", "1");
DeleteCommand deleteCommand = new DeleteCommand();
deleteCommand.execute(attrs);
System.out.flush();
String expected = "{\"status\":0,\"message\":\"OK\"}\n";
String actual = _baos.toString();
Map<String, Object> expectedMap =
new ObjectMapper().readValue(expected, new TypeReference<HashMap<String, Object>>() {
});
Map<String, Object> actualMap =
new ObjectMapper().readValue(actual, new TypeReference<HashMap<String, Object>>() {
});
assertEquals(expectedMap.get("status"), actualMap.get("status"));
}
示例13: testExecute
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
@Test
public void testExecute() throws SolrServerException, IOException {
String solrUrl = cluster.getJettySolrRunners().get(0).getBaseUrl() + "/" + COLLECTION;
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put("solr_url", solrUrl);
attrs.put("query", "SolrJ");
SearchCommand searchCommand = new SearchCommand();
searchCommand.execute(attrs);
System.out.flush();
String expected = "{\"status\":0,\"message\":\"OK\"}\n";
String actual = _baos.toString();
Map<String, Object> expectedMap =
new ObjectMapper().readValue(expected, new TypeReference<HashMap<String, Object>>() {
});
Map<String, Object> actualMap =
new ObjectMapper().readValue(actual, new TypeReference<HashMap<String, Object>>() {
});
assertEquals(expectedMap.get("status"), actualMap.get("status"));
}
示例14: json2GenericObject
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
/**
* JSON串转换为Java泛型对象,可以是各种类型,此方法最为强大。用法看测试用例。
*
* @param <T>
* @param jsonString
* JSON字符串
* @param tr
* TypeReference,例如: new TypeReference< List<FamousUser> >(){}
* @return List对象列表
*/
@SuppressWarnings("unchecked")
public static <T> T json2GenericObject(String jsonString,
TypeReference<T> tr) {
if (jsonString == null || "".equals(jsonString)) {
return null;
} else {
try {
return (T) objectMapper.readValue(jsonString, tr);
} catch (Exception e) {
log.warn("json error:" + e.getMessage());
}
}
return null;
}
示例15: verifyGoogleRecaptcha
import org.codehaus.jackson.type.TypeReference; //导入依赖的package包/类
public static boolean verifyGoogleRecaptcha(String gRecaptchaResponse, String secretKey) {
boolean result = false;
try {
ClientRequest request = new ClientRequest("https://www.google.com/recaptcha/api/siteverify");
request.formParameter("secret", secretKey);
request.formParameter("response", gRecaptchaResponse);
request.accept("application/json");
ClientResponse<String> response = request.post(String.class);
ObjectMapper mapper = new ObjectMapper();
Map<String, String> map = mapper.readValue(new ByteArrayInputStream(
response.getEntity().getBytes()), new TypeReference<Map<String, String>>() {});
return Boolean.parseBoolean(map.get("success"));
} catch (Exception e) {
log.error("Exception happened while verifying recaptcha ", e);
return result;
}
}