本文整理匯總了Java中com.fasterxml.jackson.core.type.TypeReference類的典型用法代碼示例。如果您正苦於以下問題:Java TypeReference類的具體用法?Java TypeReference怎麽用?Java TypeReference使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TypeReference類屬於com.fasterxml.jackson.core.type包,在下文中一共展示了TypeReference類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: populateDataFlows
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
private Map<String, String> populateDataFlows(Object item){
Map<String, String> mapping = new HashMap<String, String>();
LinkedHashMap<String,Object> linkedItem = (LinkedHashMap<String,Object>) item;
ArrayList<LinkedHashMap>linkedMap = (ArrayList<LinkedHashMap>) linkedItem.get("item-metadata");
String mappingAsString = null;
for(LinkedHashMap hashmap : linkedMap){
switch((String)hashmap.get("rel")){
case "Mapping JSON":
mappingAsString = (String)hashmap.get("val");
break;
}
}
mappingAsString = mappingAsString.replaceAll( "\\\\\"","\"");
ObjectMapper mapper = new ObjectMapper();
try {
mapping = mapper.readValue(mappingAsString, new TypeReference<Map<String, String>>(){});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapping;
}
示例2: data
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
@SystemControllerLog(description="權限管理-資源列表")
@RequestMapping(value = "/data")
@ResponseBody
public String data(String params,HttpSession session) {
try {
ObjectMapper om = new ObjectMapper();
Map<String, Object> map = new HashMap<String, Object>();
// 當前隻查詢管理員
if (!StringUtils.isEmpty(params)) {
// 參數處理
map = om.readValue(params, new TypeReference<Map<String, Object>>() {});
}
PagerModel<Resource > pg = resourceService.findPaginated(map);
// 序列化查詢結果為JSON
Map<String, Object> result = new HashMap<String, Object>();
result.put("total", pg.getTotal());
result.put("rows", pg.getData());
return om.writeValueAsString(result);
} catch (Exception e) {
e.printStackTrace();
return "{ \"total\" : 0, \"rows\" : [] }";
}
}
示例3: notify
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
@Post("json")
public Map<String,Object> notify(String entity) throws Exception {
List<StorageSourceNotification> notifications = null;
ObjectMapper mapper = new ObjectMapper();
notifications =
mapper.readValue(entity,
new TypeReference<List<StorageSourceNotification>>(){});
IStorageSourceService storageSource =
(IStorageSourceService)getContext().getAttributes().
get(IStorageSourceService.class.getCanonicalName());
storageSource.notifyListeners(notifications);
HashMap<String, Object> model = new HashMap<String,Object>();
model.put("output", "OK");
return model;
}
示例4: mapToNakadiEvent
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
public NakadiEvent mapToNakadiEvent(final EventLog event) {
final NakadiEvent nakadiEvent = new NakadiEvent();
final NakadiMetadata metadata = new NakadiMetadata();
metadata.setEid(convertToUUID(event.getId()));
metadata.setOccuredAt(event.getCreated());
metadata.setFlowId(event.getFlowId());
nakadiEvent.setMetadata(metadata);
HashMap<String, Object> payloadDTO;
try {
payloadDTO = objectMapper.readValue(event.getEventBodyData(), new TypeReference<LinkedHashMap<String, Object>>() { });
} catch (IOException e) {
log.error("An error occurred at JSON deserialization", e);
throw new UncheckedIOException(e);
}
nakadiEvent.setData(payloadDTO);
return nakadiEvent;
}
開發者ID:zalando-nakadi,項目名稱:nakadi-producer-spring-boot-starter,代碼行數:22,代碼來源:EventTransmissionService.java
示例5: messageReceived
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
@StreamListener(target = Sink.INPUT)
@Transactional
public void messageReceived(String messageJson) throws Exception {
Message<JsonNode> message = new ObjectMapper().readValue( //
messageJson, //
new TypeReference<Message<JsonNode>>() {});
String type = "Event";
if (message.getMessageType().endsWith("Command")) {
type = "Command";
}
PastEvent event = new PastEvent( //
type, //
message.getMessageType(), //
message.getTraceId(), //
message.getSender(), //
message.getPayload().toString());
// save
LogRepository.instance.addEvent(event);
// and probably send to connected websocket (TODO: Not a good place for the code here!)
simpMessageTemplate.convertAndSend("/topic/events", event);
}
示例6: orderPlacedReceived
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
/**
* Handles incoming OrderPlacedEvents.
*
* Using the conditional {@link StreamListener} from
* https://github.com/spring-cloud/spring-cloud-stream/blob/master/spring-cloud-stream-core-docs/src/main/asciidoc/spring-cloud-stream-overview.adoc
* in a way close to what Axion
* would do (see e.g. https://dturanski.wordpress.com/2017/03/26/spring-cloud-stream-for-event-driven-architectures/)
*/
@StreamListener(target = Sink.INPUT,
condition="payload.messageType.toString()=='OrderPlacedEvent'")
@Transactional
public void orderPlacedReceived(String messageJson) throws JsonParseException, JsonMappingException, IOException {
Message<Order> message = new ObjectMapper().readValue(messageJson, new TypeReference<Message<Order>>(){});
Order order = message.getPayload();
System.out.println("New order placed, start flow. " + order);
// persist domain entity
repository.persistOrder(order);
// and kick of a new flow instance
camunda.getRuntimeService().createMessageCorrelation(message.getMessageType())
.processInstanceBusinessKey(message.getTraceId())
.setVariable("orderId", order.getId())
.correlateWithResult();
}
示例7: testPrefer
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
@Test
public void testPrefer() throws IOException {
final Response res = target(RESOURCE_PATH).request()
.header("Prefer", "return=representation; include=\"" + Trellis.PreferServerManaged.getIRIString() + "\"")
.accept("application/ld+json; profile=\"http://www.w3.org/ns/json-ld#compacted\"").get();
assertEquals(OK, res.getStatusInfo());
final String entity = IOUtils.toString((InputStream) res.getEntity(), UTF_8);
final Map<String, Object> obj = MAPPER.readValue(entity, new TypeReference<Map<String, Object>>(){});
assertTrue(obj.containsKey("@context"));
assertTrue(obj.containsKey("title"));
assertFalse(obj.containsKey("mode"));
assertTrue(obj.containsKey("created"));
assertEquals("A title", (String) obj.get("title"));
}
示例8: mainFlow
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
@Override
protected void mainFlow(UsecaseExecution<Parameters, InstagramResponse<List<User>>> execution) throws Exception {
String endpoint = String.format(
"https://api.instagram.com/v1/users/%s/follows?access_token=%s",
execution.params.user_id,
execution.params.access_token);
URL url = new URL(endpoint);
URLConnection connection = url.openConnection();
InputStream is = connection.getInputStream();
try {
execution.result = MAPPER.readValue(is, new TypeReference<InstagramResponse<List<User>>>() {
});
} finally {
is.close();
}
execution.result_type = UsecaseResultType.SUCCESS;
}
示例9: testCanGetJobInputs
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
@Test
public void testCanGetJobInputs() throws IOException {
final APIJobRequest req = REQUEST_AGAINST_FIRST_SPEC;
final JobId jobId = generateAuthenticatedRequest(RULE, HTTP_JOBS_PATH)
.post(json(req))
.readEntity(APIJobCreatedResponse.class)
.getId();
final Response jobInputsResponse =
generateAuthenticatedRequest(RULE, jobResourceSubpath(jobId + "/inputs"))
.get();
assertThat(jobInputsResponse.getStatus()).isEqualTo(OK);
final String responseJson = jobInputsResponse.readEntity(String.class);
final Map<JobExpectedInputId, JsonNode> inputsReturned =
readJSON(responseJson, new TypeReference<Map<JobExpectedInputId, JsonNode>>() {});
assertThat(inputsReturned).isEqualTo(req.getInputs());
}
示例10: processEvaluationFileForBuilding
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
private long processEvaluationFileForBuilding(long buildingId) throws Exception {
mockMvc.perform(MockMvcRequestBuilders.fileUpload("/position/processEvalFiles")
.file(evaluationFile)
.param("buildingIdentifier", String.valueOf(buildingId)))
.andExpect(status().isOk());
ResultActions getEvalFileResultActions = mockMvc.perform(get("/position/getEvalFilesForBuildingId?" +
"buildingIdentifier=" + buildingId));
getEvalFileResultActions.andExpect(status().isOk());
String getEvalFileResult = getEvalFileResultActions.andReturn().getResponse().getContentAsString();
List<GetEvaluationFilesForBuilding> getEvaluationFilesForBuilding = (List<GetEvaluationFilesForBuilding>)
this.objectMapper.readValue(getEvalFileResult, new TypeReference<List<GetEvaluationFilesForBuilding>>() {
});
assertTrue("The returned list of type " + GetEvaluationFilesForBuilding.class.getSimpleName() + " had an unexpected size.",
getEvaluationFilesForBuilding.size() == 1);
return getEvaluationFilesForBuilding.get(0).getId();
}
示例11: deserializeResponse
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
@Override
public File deserializeResponse(String answer) throws TelegramApiRequestException {
try {
ApiResponse<File> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<File>>(){});
if (result.getOk()) {
return result.getResult();
} else {
throw new TelegramApiRequestException("Error getting file", result);
}
} catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e);
}
}
示例12: shouldThrowIfAnExtraordinaryExceptionHappensWhenParsingAsGenericMap
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
@Test
public void shouldThrowIfAnExtraordinaryExceptionHappensWhenParsingAsGenericMap() throws Exception {
JsonNode value = mock(ObjectNode.class);
when(value.getNodeType()).thenReturn(JsonNodeType.OBJECT);
JsonNodeClaim claim = (JsonNodeClaim) claimFromNode(value);
JsonNodeClaim spiedClaim = spy(claim);
ObjectMapper mockedMapper = mock(ObjectMapper.class);
when(spiedClaim.getObjectMapper()).thenReturn(mockedMapper);
JsonParser mockedParser = mock(JsonParser.class);
when(mockedMapper.treeAsTokens(value)).thenReturn(mockedParser);
when(mockedParser.readValueAs(ArgumentMatchers.any(TypeReference.class))).thenThrow(IOException.class);
exception.expect(JWTDecodeException.class);
spiedClaim.asMap();
}
示例13: getEnvironmentVariables
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
public static List<EnvironmentVariable> getEnvironmentVariables(String response) {
List<EnvironmentVariable> environmentVariables = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
try {
environmentVariables = mapper.readValue(response, new TypeReference<List<EnvironmentVariable>>() {
});
} catch (IOException e) {
e.printStackTrace();
}
return environmentVariables;
}
示例14: fromString
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
public static <T> T fromString(String string, TypeReference<T> typeReference) {
try {
return OBJECT_MAPPER.readValue(string, typeReference);
} catch (IOException e) {
throw new IllegalArgumentException("The given string value: " + string + " cannot be transformed to Json object", e);
}
}
示例15: json2map
import com.fasterxml.jackson.core.type.TypeReference; //導入依賴的package包/類
/**
* json string convert to map with javaBean
*/
public static <T> Map<String, T> json2map(String jsonStr, Class<T> clazz)
throws Exception {
Map<String, Map<String, Object>> map = OBJECT_MAPPER.readValue(jsonStr,
new TypeReference<Map<String, T>>() {
});
Map<String, T> result = new HashMap<String, T>();
for (Map.Entry<String, Map<String, Object>> entry : map.entrySet()) {
result.put(entry.getKey(), map2pojo(entry.getValue(), clazz));
}
return result;
}