List of usage examples for com.fasterxml.jackson.databind.type TypeFactory defaultInstance
public static TypeFactory defaultInstance()
From source file:org.brutusin.json.impl.JacksonCodec.java
@Override public Object parse(String json, Type type) throws ParseException { if (json == null || json.trim().isEmpty()) { return null; }//ww w. j a va 2s . c om try { JavaType jt = TypeFactory.defaultInstance().constructType(type); return mapper.readValue(json, jt); } catch (JsonParseException ex) { throw new ParseException(ex); } catch (JsonMappingException ex) { throw new RuntimeException(ex); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:org.osiam.client.AbstractOsiamService.java
protected SCIMSearchResult<T> searchResources(Query query, AccessToken accessToken) { checkNotNull(query, "The given query must not be null."); checkAccessTokenIsNotNull(accessToken); StatusType status;//from w w w .ja v a2s . co m String content; try { Response response = targetEndpoint.path(typeName + "s").queryParam("attributes", query.getAttributes()) .queryParam("filter", query.getFilter()).queryParam("sortBy", query.getSortBy()) .queryParam("sortOrder", query.getSortOrder()) .queryParam("startIndex", query.getStartIndex() != QueryBuilder.DEFAULT_START_INDEX ? query.getStartIndex() : null) .queryParam("count", query.getCount() != QueryBuilder.DEFAULT_COUNT ? query.getCount() : null) .request(MediaType.APPLICATION_JSON).header(AUTHORIZATION, BEARER + accessToken.getToken()) .get(); status = response.getStatusInfo(); content = response.readEntity(String.class); } catch (ProcessingException e) { throw new ConnectionInitializationException(CONNECTION_SETUP_ERROR_STRING, e); } checkAndHandleResponse(content, status, accessToken, String.format("search with query: %s", query), null); try { JavaType queryResultType = TypeFactory.defaultInstance().constructParametricType(SCIMSearchResult.class, type); return mapper.readValue(content, queryResultType); } catch (IOException e) { throw new OsiamClientException(String.format("Unable to deserialize search result: %s", content), e); } }
From source file:io.dacopancm.socketdcm.helper.HelperUtil.java
public static List<StreamFile> fromJSON(final String jsonPacket) { List<StreamFile> data = null; try {/* w w w.j av a 2 s . co m*/ data = new ObjectMapper().readValue(jsonPacket, TypeFactory.defaultInstance().constructCollectionType(List.class, StreamFile.class)); } catch (Exception e) { // Handle the problem System.out.println(e.getMessage()); } return data; }
From source file:org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapperTest.java
@Test public void shouldLookInTheValueClassIdFieldNameToFindTheValueClassIDWhenClassIdIsAMap() { properties.getHeaders().put("keyType", "java.lang.Integer"); properties.getHeaders().put(javaTypeMapper.getContentClassIdFieldName(), "java.lang.String"); properties.getHeaders().put(javaTypeMapper.getClassIdFieldName(), HashMap.class.getName()); given(javaTypeMapper.getKeyClassIdFieldName()).willReturn("keyType"); JavaType javaType = javaTypeMapper.toJavaType(properties); assertThat((MapType) javaType, equalTo( TypeFactory.defaultInstance().constructMapType(HashMap.class, Integer.class, String.class))); }
From source file:io.fabric8.jolokia.facade.FabricMBeanFacadeTest.java
@Test public void testGetProfilesFields() { // this can only be run if you have a fabric running... Assume.assumeTrue(Boolean.valueOf(System.getProperty("hasFabric"))); FabricMBean facade = getFabricMBean(); String json = facade.getProfiles("1.0", Helpers.toList("id")); try {/*from w ww .ja va2s . c om*/ Collection<ProfileDTO> profiles = Helpers.getObjectMapper().readValue(json, TypeFactory.defaultInstance().constructParametricType(Collection.class, ProfileDTO.class)); Assume.assumeNotNull(profiles); for (ProfileDTO profile : profiles) { System.out.println(profile); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.palantir.typescript.services.language.LanguageEndpoint.java
public List<DiagnosticEx> getDiagnostics(String serviceKey, String fileName, boolean semantic) { checkNotNull(serviceKey);//from w w w.j a v a 2 s . c om checkNotNull(fileName); Request request = new Request(SERVICE, "getDiagnostics", serviceKey, fileName, semantic); CollectionType resultType = TypeFactory.defaultInstance().constructCollectionType(List.class, DiagnosticEx.class); return this.bridge.call(request, resultType); }
From source file:com.netflix.genie.web.tasks.leader.ClusterCheckerTask.java
private boolean isNodeHealthy(final String host) { ///*from w w w.j a v a 2 s. co m*/ // A node is valid and healthy if all health indicators excluding the ones mentioned in healthIndicatorsToIgnore // are UP. // boolean result = true; try { restTemplate.getForObject(this.scheme + host + this.healthEndpoint, String.class); } catch (final HttpStatusCodeException e) { log.error("Failed validating host {}", host, e); try { final Map<String, Object> responseMap = mapper.readValue(e.getResponseBodyAsByteArray(), TypeFactory.defaultInstance().constructMapType(Map.class, String.class, Object.class)); for (Map.Entry<String, Object> responseEntry : responseMap.entrySet()) { if (responseEntry.getValue() instanceof Map && !healthIndicatorsToIgnore.contains(responseEntry.getKey()) && !Status.UP.getCode().equals(((Map) responseEntry.getValue()).get(PROPERTY_STATUS))) { result = false; break; } } } catch (Exception ex) { log.error("Failed reading the error response when validating host {}", host, ex); result = false; } } catch (final Exception e) { log.error("Unable to reach {}", host, e); result = false; } return result; }
From source file:org.apache.servicecomb.common.rest.codec.param.BodyProcessorCreator.java
@Override public ParamValueProcessor create(Parameter parameter, Type genericParamType) { JavaType targetType = TypeFactory.defaultInstance().constructType(genericParamType); boolean rawJson = ClassUtils.isRawJsonType(parameter); if (genericParamType.getTypeName().equals(String.class.getTypeName()) && rawJson) { return new RawJsonBodyProcessor(targetType, parameter.getRequired()); }/*from w w w . j a v a 2 s .co m*/ return new BodyProcessor(targetType, parameter.getRequired()); }
From source file:io.fabric8.jolokia.facade.FabricMBeanFacadeTest.java
@Test public void testGetProfileIds() { // this can only be run if you have a fabric running... Assume.assumeTrue(Boolean.valueOf(System.getProperty("hasFabric"))); FabricMBean facade = getFabricMBean(); String json = facade.getProfileIds("1.0"); try {/*from w w w.j a v a2 s. c om*/ Collection<String> profiles = Helpers.getObjectMapper().readValue(json, TypeFactory.defaultInstance().constructParametricType(Collection.class, String.class)); Assume.assumeNotNull(profiles); for (String profile : profiles) { System.out.println("Profile id:" + profile); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.palantir.typescript.services.language.LanguageEndpoint.java
public List<TextChange> getFormattingEditsForRange(String serviceKey, String fileName, int start, int end, FormatCodeOptions options) {//w ww .j a v a 2s . c o m checkNotNull(serviceKey); checkNotNull(fileName); checkArgument(start >= 0); checkArgument(end >= 0); checkNotNull(options); Request request = new Request(SERVICE, "getFormattingEditsForRange", serviceKey, fileName, start, end, options); CollectionType resultType = TypeFactory.defaultInstance().constructCollectionType(List.class, TextChange.class); return this.bridge.call(request, resultType); }