use of com.fasterxml.jackson.core.type.TypeReference in project riposte by Nike-Inc.
the class BackstopperRiposteFrameworkErrorHandlerListenerTest method shouldHandleRequestContentDeserializationException.
@Test
public void shouldHandleRequestContentDeserializationException() {
RequestInfo requestInfo = new RequestInfoImpl(null, HttpMethod.PATCH, null, null, null, null, null, null, null, false, true, false);
verifyExceptionHandled(new RequestContentDeserializationException("intentional boom", null, requestInfo, new TypeReference<Object>() {
}), singletonError(testProjectApiErrors.getMalformedRequestApiError()));
}
use of com.fasterxml.jackson.core.type.TypeReference in project helios by spotify.
the class CliHostListTest method testStatusFilter.
@Test
public void testStatusFilter() throws Exception {
String jsonOutput = cli("hosts", "-f", "--json", "--status", "UP");
Map<String, HostStatus> statuses = Json.readUnchecked(jsonOutput, new TypeReference<Map<String, HostStatus>>() {
});
final HeliosClient client = defaultClient();
Map<String, HostStatus> expectedStatuses = client.hostStatuses(ImmutableList.of(hostname1)).get();
assertThat(expectedStatuses, equalTo(statuses));
jsonOutput = cli("hosts", "-f", "--json", "--status", "DOWN");
statuses = Json.readUnchecked(jsonOutput, new TypeReference<Map<String, HostStatus>>() {
});
expectedStatuses = client.hostStatuses(ImmutableList.of(hostname2)).get();
assertThat(expectedStatuses, equalTo(statuses));
}
use of com.fasterxml.jackson.core.type.TypeReference in project iris by chicc999.
the class JsonUtil method readMapValue.
/**
* 从json串中获取一个map,容器中元素为类型为key,value
* @param content
* @param key
* @param value
* @param <K>
* @param <V>
* @return
* @throws IOException
*/
public static <K, V> Map<K, V> readMapValue(String content, Class<K> key, Class<V> value) throws IOException {
ArgumentUtil.isNotBlank(content);
Map<K, V> map;
try {
map = mapper.readValue(content, new TypeReference<Map<K, V>>() {
});
} catch (Exception e) {
throw new IOException("反序列化失败", e);
}
return map;
}
use of com.fasterxml.jackson.core.type.TypeReference in project dhis2-core by dhis2.
the class EditSMSCommandForm method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
Set<SMSCode> codeSet = new HashSet<>();
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readValue(codeDataelementOption, JsonNode.class);
JsonNode codes = root.get("codes");
if (codes != null && codes.size() > 0) {
codes.iterator().forEachRemaining(code -> {
if (code.get("code") != null && code.get("dataElementId") != null && code.get("optionId") != null && code.get("formula") != null) {
SMSCode c = new SMSCode();
c.setCode(code.get("code").asText());
c.setDataElement(dataElementService.getDataElement(code.get("dataElementId").asInt()));
c.setOptionId(code.get("optionId").asInt());
if (!StringUtils.isEmpty(code.get("formula").asText())) {
c.setFormula(code.get("formula").asText());
} else {
c.setFormula(null);
}
codeSet.add(c);
}
});
}
Set<SMSSpecialCharacter> specialCharacterSet = new HashSet<>();
root = mapper.readValue(specialCharactersInfo, JsonNode.class);
JsonNode specialChars = root.get("specialCharacters");
if (specialChars != null && StringUtils.isNoneEmpty(specialChars.toString())) {
specialCharacterSet = mapper.readValue(specialChars.toString(), new TypeReference<HashSet<SMSSpecialCharacter>>() {
});
smsCommandService.saveSpecialCharacterSet(specialCharacterSet);
}
SMSCommand command = getSMSCommand();
if (selectedDataSetID > -1 && command != null) {
if (command.getParserType() == ParserType.TRACKED_ENTITY_REGISTRATION_PARSER) {
root = mapper.readValue(trackedEntityAttributeCodes, JsonNode.class);
JsonNode regCodes = root.get("trackedEntityAttributeCodes");
if (regCodes != null && regCodes.size() > 0) {
regCodes.iterator().forEachRemaining(regCode -> {
if (regCode.get("code") != null && regCode.get("trackedEntityAttributeId") != null) {
SMSCode c = new SMSCode();
c.setCode(regCode.get("code").asText());
c.setTrackedEntityAttribute(trackedEntityAttributeService.getTrackedEntityAttribute(regCode.get("trackedEntityAttributeId").asInt()));
codeSet.add(c);
}
});
}
}
if (command.getParserType() == ParserType.EVENT_REGISTRATION_PARSER) {
root = mapper.readValue(programStageDataElementCodes, JsonNode.class);
JsonNode regCodes = root.get("programStageDataElementCodes");
if (regCodes != null && regCodes.size() > 0) {
regCodes.iterator().forEachRemaining(regCode -> {
if (regCode.get("code") != null && regCode.get("programStageDataElementId") != null) {
SMSCode c = new SMSCode();
c.setCode(regCode.get("code").asText());
c.setDataElement(dataElementService.getDataElement(regCode.get("programStageDataElementId").asInt()));
c.setCompulsory(regCode.get("compulsory").asBoolean());
codeSet.add(c);
}
});
}
}
}
if (codeSet.size() > 0) {
smsCommandService.save(codeSet);
}
if (selectedDataSetID > -1 && command != null) {
command.setCurrentPeriodUsedForReporting(currentPeriodUsedForReporting);
command.setName(name);
command.setSeparator(separator);
if (completenessMethod != null) {
command.setCompletenessMethod(completenessMethod);
}
// remove codes
Set<SMSCode> toRemoveCodes = command.getCodes();
smsCommandService.deleteCodeSet(toRemoveCodes);
// remove special characters
Set<SMSSpecialCharacter> toRemoveCharacters = command.getSpecialCharacters();
smsCommandService.deleteSpecialCharacterSet(toRemoveCharacters);
command.setCodes(codeSet);
// message
command.setDefaultMessage(defaultMessage);
command.setReceivedMessage(receivedMessage);
command.setMoreThanOneOrgUnitMessage(moreThanOneOrgUnitMessage);
command.setNoUserMessage(noUserMessage);
command.setWrongFormatMessage(wrongFormatMessage);
command.setSuccessMessage(successMessage);
if (userGroupID != null && userGroupID > -1) {
command.setUserGroup(userGroupService.getUserGroup(userGroupID));
}
command.setSpecialCharacters(specialCharacterSet);
smsCommandService.save(command);
}
return SUCCESS;
}
use of com.fasterxml.jackson.core.type.TypeReference in project nem2-sdk-java by nemtech.
the class AccountHttp method getAccountsInfo.
@Override
public Observable<List<AccountInfo>> getAccountsInfo(List<Address> addresses) {
JsonObject requestBody = new JsonObject();
requestBody.put("addresses", addresses.stream().map(address -> address.plain()).collect(Collectors.toList()));
Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable();
return networkTypeResolve.flatMap(networkType -> this.client.postAbs(this.url.toString()).as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<AccountInfoDTO>>readValue(json.toString(), new TypeReference<List<AccountInfoDTO>>() {
})).flatMapIterable(item -> item).map(AccountInfoDTO::getAccount).map(accountDTO -> new AccountInfo(Address.createFromRawAddress(accountDTO.getAddressEncoded()), accountDTO.getAddressHeight().extractIntArray(), accountDTO.getPublicKey(), accountDTO.getPublicKeyHeight().extractIntArray(), accountDTO.getImportance().extractIntArray(), accountDTO.getImportanceHeight().extractIntArray(), accountDTO.getMosaics().stream().map(mosaicDTO -> new Mosaic(new MosaicId(mosaicDTO.getId().extractIntArray()), mosaicDTO.getAmount().extractIntArray())).collect(Collectors.toList()))).toList().toObservable());
}
Aggregations