当前位置: 首页>>代码示例>>Java>>正文


Java TypeReference类代码示例

本文整理汇总了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);
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:21,代码来源:DeviceTagsTest.java

示例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;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:17,代码来源:JsonConverter.java

示例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;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:17,代码来源:JsonConverter.java

示例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");

}
 
开发者ID:telefonicaid,项目名称:fiware-sinfonier,代码行数:18,代码来源:ConditionalFields.java

示例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);
	}

}
 
开发者ID:telefonicaid,项目名称:fiware-sinfonier,代码行数:23,代码来源:Conditional.java

示例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();
        }
    }
}
 
开发者ID:telefonicaid,项目名称:fiware-sinfonier,代码行数:18,代码来源:BaseSinfonierBolt.java

示例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();
        }
    }
}
 
开发者ID:telefonicaid,项目名称:fiware-sinfonier,代码行数:18,代码来源:BaseSinfonierDrain.java

示例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;
}
 
开发者ID:shuqin,项目名称:ALLIN,代码行数:22,代码来源:BaseParser.java

示例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;
}
 
开发者ID:gerritjvv,项目名称:bigstreams,代码行数:35,代码来源:FileTrackingStatusFormatter.java

示例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;
}
 
开发者ID:mosuka,项目名称:solrj-example,代码行数:17,代码来源:SolrJExampleUtil.java

示例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"));
}
 
开发者ID:mosuka,项目名称:solrj-example,代码行数:27,代码来源:DeleteCommandTest.java

示例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"));
}
 
开发者ID:mosuka,项目名称:solrj-example,代码行数:27,代码来源:SearchCommandTest.java

示例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;
}
 
开发者ID:neoremind,项目名称:fountain,代码行数:26,代码来源:JsonUtils.java

示例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;
	}
}
 
开发者ID:AgarwalNeha1,项目名称:gluu,代码行数:21,代码来源:RecaptchaUtils.java


注:本文中的org.codehaus.jackson.type.TypeReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。