Search in sources :

Example 31 with TypeReference

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()));
}
Also used : RequestContentDeserializationException(com.nike.riposte.server.error.exception.RequestContentDeserializationException) RequestInfoImpl(com.nike.riposte.server.http.impl.RequestInfoImpl) TypeReference(com.fasterxml.jackson.core.type.TypeReference) RequestInfo(com.nike.riposte.server.http.RequestInfo) Test(org.junit.Test)

Example 32 with TypeReference

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));
}
Also used : HostStatus(com.spotify.helios.common.descriptors.HostStatus) TypeReference(com.fasterxml.jackson.core.type.TypeReference) HeliosClient(com.spotify.helios.client.HeliosClient) Map(java.util.Map) Test(org.junit.Test)

Example 33 with TypeReference

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;
}
Also used : TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 34 with TypeReference

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;
}
Also used : SMSCommand(org.hisp.dhis.sms.command.SMSCommand) SMSCode(org.hisp.dhis.sms.command.code.SMSCode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SMSSpecialCharacter(org.hisp.dhis.sms.command.SMSSpecialCharacter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet)

Example 35 with TypeReference

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());
}
Also used : Mosaic(io.nem.sdk.model.mosaic.Mosaic) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) MalformedURLException(java.net.MalformedURLException) AggregateTransaction(io.nem.sdk.model.transaction.AggregateTransaction) HashMap(java.util.HashMap) NetworkType(io.nem.sdk.model.blockchain.NetworkType) Collectors(java.util.stream.Collectors) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) BodyCodec(io.vertx.reactivex.ext.web.codec.BodyCodec) Function(io.reactivex.functions.Function) io.nem.sdk.model.account(io.nem.sdk.model.account) Map(java.util.Map) Optional(java.util.Optional) Transaction(io.nem.sdk.model.transaction.Transaction) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) MosaicId(io.nem.sdk.model.mosaic.MosaicId) NetworkType(io.nem.sdk.model.blockchain.NetworkType) MosaicId(io.nem.sdk.model.mosaic.MosaicId) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Mosaic(io.nem.sdk.model.mosaic.Mosaic)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)87 IOException (java.io.IOException)34 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)31 Test (org.junit.Test)25 Map (java.util.Map)19 List (java.util.List)16 HashMap (java.util.HashMap)12 ArrayList (java.util.ArrayList)11 StringWriter (java.io.StringWriter)8 BaseMandrillAnonymousListResponse (com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillAnonymousListResponse)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 InputStream (java.io.InputStream)7 MalformedURLException (java.net.MalformedURLException)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Collectors (java.util.stream.Collectors)5 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)4 AuditInfo (io.druid.audit.AuditInfo)4 PublicAccount (io.nem.sdk.model.account.PublicAccount)4 NetworkType (io.nem.sdk.model.blockchain.NetworkType)4 NamespaceId (io.nem.sdk.model.namespace.NamespaceId)4