List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference
protected TypeReference()
From source file:com.basistech.rosette.dm.json.plain.ListAttributeDeserializerTest.java
@Test public void isolatedInOrder() throws Exception { /*/*from w w w . ja v a 2 s . c o m*/ * a list of tokens not in an AnnotatedText. There's no 'type' handling, just our * custom itemType to worry over. */ ListAttribute<Token> tokens = mapper.readValue(new File("test-data/ordered-list.json"), new TypeReference<ListAttribute<Token>>() { }); assertEquals(3, tokens.size()); for (Object token : tokens) { assertTrue(token instanceof Token); } assertEquals(Lists.newArrayList("val1"), tokens.getExtendedProperties().get("ext1")); assertEquals("val2", tokens.getExtendedProperties().get("ext2")); }
From source file:com.nesscomputing.jackson.datatype.CommonsLang3SerializerTest.java
@Test public void testEntryCrossover() throws IOException { Entry<String, Boolean> pair = Maps.immutableEntry("foo", true); Pair<String, Boolean> newPair = mapper.readValue(mapper.writeValueAsBytes(pair), new TypeReference<Pair<String, Boolean>>() { });/*from ww w. j ava 2s . c o m*/ assertEquals(pair.getKey(), newPair.getKey()); assertEquals(pair.getValue(), newPair.getValue()); pair = mapper.readValue(mapper.writeValueAsBytes(newPair), new TypeReference<Entry<String, Boolean>>() { }); assertEquals(newPair.getKey(), pair.getKey()); assertEquals(newPair.getValue(), pair.getValue()); }
From source file:io.microprofile.showcase.speaker.domain.VenueJavaOne2016Test.java
@Test public void readSpeakers() throws Exception { final ObjectMapper om = new ObjectMapper(); final InputStream is = this.getClass().getResourceAsStream("/speakers.json"); final Set<Speaker> speakers = om.readValue(is, new TypeReference<Set<Speaker>>() { });/*w ww .ja v a2 s.c om*/ Assert.assertFalse("Failed to get any speakers", speakers.isEmpty()); for (final Speaker speaker : speakers) { Assert.assertNotNull(speaker.getNameLast()); this.log.info(speaker.getNameFirst() + " " + speaker.getNameLast()); } }
From source file:com.evrythng.java.wrapper.util.JSONUtilsTest.java
@Test public void deserialize() { String json = "{\"myProp\":\" 1 \",\"b\":2, \"sub\": {\"x\":14,\"y\":33} }"; MyObject o = JSONUtils.read(json, new TypeReference<MyObject>() { });/* w ww . j a v a 2s .c o m*/ Assert.assertEquals("1", o.getMyProp()); Assert.assertEquals(Integer.valueOf(2), o.getB()); Assert.assertNotNull(o.getSub()); Assert.assertSame(MySubObject.class, o.getSub().getClass()); Assert.assertEquals(Integer.valueOf(14), o.getSub().getX()); Assert.assertEquals(Integer.valueOf(33), o.getSub().getY()); }
From source file:com.netflix.edda.EddaCloudWatchClient.java
public DescribeAlarmsResult describeAlarms(DescribeAlarmsRequest request) { validateEmpty("ActionPrefix", request.getActionPrefix()); validateEmpty("AlarmNamePrefix", request.getAlarmNamePrefix()); TypeReference<List<MetricAlarm>> ref = new TypeReference<List<MetricAlarm>>() { };/*from www . j a v a 2 s .com*/ String url = config.url() + "/api/v2/aws/alarms;_expand"; try { List<MetricAlarm> metricAlarms = parse(ref, doGet(url)); List<String> names = request.getAlarmNames(); String state = request.getStateValue(); if (shouldFilter(names) || shouldFilter(state)) { List<MetricAlarm> mas = new ArrayList<MetricAlarm>(); for (MetricAlarm ma : metricAlarms) { if (matches(names, ma.getAlarmName()) && matches(state, ma.getStateValue())) mas.add(ma); } metricAlarms = mas; } return new DescribeAlarmsResult().withMetricAlarms(metricAlarms); } catch (IOException e) { throw new AmazonClientException("Faled to parse " + url, e); } }
From source file:com.netflix.edda.EddaAutoScalingClient.java
public DescribeAutoScalingGroupsResult describeAutoScalingGroups(DescribeAutoScalingGroupsRequest request) { TypeReference<List<AutoScalingGroup>> ref = new TypeReference<List<AutoScalingGroup>>() { };//from ww w .j a v a 2 s. c o m String url = config.url() + "/api/v2/aws/autoScalingGroups;_expand"; try { List<AutoScalingGroup> autoScalingGroups = parse(ref, doGet(url)); List<String> names = request.getAutoScalingGroupNames(); if (shouldFilter(names)) { List<AutoScalingGroup> asgs = new ArrayList<AutoScalingGroup>(); for (AutoScalingGroup asg : autoScalingGroups) { if (matches(names, asg.getAutoScalingGroupName())) asgs.add(asg); } autoScalingGroups = asgs; } return new DescribeAutoScalingGroupsResult().withAutoScalingGroups(autoScalingGroups); } catch (IOException e) { throw new AmazonClientException("Faled to parse " + url, e); } }
From source file:com.evrythng.java.wrapper.service.PlaceService.java
/** * Retrieves list of all {@link Place} resources. * <p>/* ww w .j a va 2 s.c om*/ * GET {@value #PATH_PLACES} * * @return a preconfigured {@link Builder} */ public Builder<List<Place>> placesReader() throws EvrythngClientException { return get(PATH_PLACES, new TypeReference<List<Place>>() { }); }
From source file:spring.travel.site.services.WeatherService.java
public CompletableFuture<Optional<DailyForecast>> forecast(Location location, int numberOfDays) { String url = url(location.getCityId(), numberOfDays); DailyForecast dailyForecast = weatherCache.getIfPresent(url); if (dailyForecast != null) { return some(dailyForecast); }/*from w ww . j a va 2s. c o m*/ return client.get(url, new TypeReference<Optional<DailyForecast>>() { }).handle(withFallback(Optional.<DailyForecast>empty())) .whenComplete((result, t) -> result.ifPresent(r -> weatherCache.put(url, r))); }
From source file:com.vmware.photon.controller.api.client.resource.SystemStatusRestApi.java
/** * Get system status.//ww w . ja v a 2 s.com * * @return {@link SystemStatus} details * @throws java.io.IOException */ @Override public SystemStatus getSystemStatus() throws IOException { String path = getBasePath(); HttpResponse httpResponse = this.restClient.perform(RestClient.Method.GET, path, null); this.restClient.checkResponse(httpResponse, HttpStatus.SC_OK); return this.restClient.parseHttpResponse(httpResponse, new TypeReference<SystemStatus>() { }); }
From source file:uk.co.sdev.async.http.ning.Sequential2CompletableFutureClientTest.java
@Override protected CompletableFuture<List<Booking>> findBookings(User user) throws IOException { return completableFutureClient .get("http://localhost:9101/bookings/" + user.getId(), new TypeReference<List<Booking>>() { }).handle(withFallback(Collections.<Booking>emptyList())); }