Example usage for com.fasterxml.jackson.core.type TypeReference TypeReference

List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core.type TypeReference TypeReference.

Prototype

protected TypeReference() 

Source Link

Usage

From source file:com.okta.sdk.clients.SessionApiClient.java

public Session createSessionWithCredentials(String username, String password) throws IOException {
    Credentials credentials = new Credentials();
    credentials.setUsername(username);/*from  w  ww .  j av  a2  s .c  o m*/
    credentials.setPassword(password);
    return post(getEncodedPath("/"), credentials, new TypeReference<Session>() {
    });
}

From source file:com.netflix.suro.jackson.TestJackson.java

@Test
public void test() throws IOException {
    String spec = "{\"a\":\"aaa\", \"b\":\"bbb\"}";

    ObjectMapper mapper = new DefaultObjectMapper();
    final Map<String, Object> injectables = Maps.newHashMap();

    injectables.put("test", "test");
    injectables.put("b", "binjected");
    mapper.setInjectableValues(new InjectableValues() {
        @Override/*from   w ww. ja v a  2  s.  c o  m*/
        public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty,
                Object beanInstance) {
            return injectables.get(valueId);
        }
    });

    TestClass test = mapper.readValue(spec, new TypeReference<TestClass>() {
    });
    assertEquals(test.getTest(), "test");
    assertEquals(test.getB(), "bbb");
}

From source file:jp.or.openid.eiwg.listener.InitListener.java

/**
 * Web???//from   w ww  . j a va 2s.com
 *
 * @param contextEvent 
 */
@Override
public void contextInitialized(ServletContextEvent contextEvent) {

    // ?
    ServletContext context = contextEvent.getServletContext();

    // ??DBLDAP????
    // ????????
    ObjectMapper mapper = new ObjectMapper();

    Map<String, Object> serviceProviderConfigs = null;
    ArrayList<LinkedHashMap<String, Object>> resourceTypes = null;
    ArrayList<LinkedHashMap<String, Object>> schemas = null;
    ArrayList<LinkedHashMap<String, Object>> users = null;

    // ?(ServiceProviderConfigs.json)??
    try {
        serviceProviderConfigs = mapper.readValue(
                new File(context.getRealPath("/WEB-INF/ServiceProviderConfigs.json")),
                new TypeReference<LinkedHashMap<String, Object>>() {
                });
    } catch (IOException e) {
        e.printStackTrace();
    }

    // (ResourceTypes.json)??
    try {
        resourceTypes = mapper.readValue(new File(context.getRealPath("/WEB-INF/ResourceTypes.json")),
                new TypeReference<ArrayList<LinkedHashMap<String, Object>>>() {
                });
    } catch (IOException e) {
        e.printStackTrace();
    }

    // (Schemas.json)??
    try {
        schemas = mapper.readValue(new File(context.getRealPath("/WEB-INF/Schemas.json")),
                new TypeReference<ArrayList<LinkedHashMap<String, Object>>>() {
                });
    } catch (IOException e) {
        e.printStackTrace();
    }

    // ??
    try {
        users = mapper.readValue(new File(context.getRealPath("/WEB-INF/Users.json")),
                new TypeReference<ArrayList<LinkedHashMap<String, Object>>>() {
                });
    } catch (IOException e) {
        e.printStackTrace();
    }

    // ?
    context.setAttribute("ServiceProviderConfigs", serviceProviderConfigs);
    context.setAttribute("ResourceTypes", resourceTypes);
    context.setAttribute("Schemas", schemas);
    context.setAttribute("Users", users);
}

From source file:org.redisson.spring.cache.CacheConfigSupport.java

public Map<String, CacheConfig> fromJSON(InputStream inputStream) throws IOException {
    return jsonMapper.readValue(inputStream, new TypeReference<Map<String, CacheConfig>>() {
    });/*www  .  ja v  a  2 s.c  o m*/
}

From source file:uk.co.sdev.async.http.ning.ObservableClientTest.java

private Observable<Optional<Bar>> getOptionalBar() throws IOException {
    return observableClient.get("http://localhost:9101/bar", new TypeReference<Optional<Bar>>() {
    });/*from ww w  . j av  a2  s .com*/
}

From source file:com.googlecode.batchfb.test.PagedTest.java

/**
 * Tests using the normal graph() call to get paged data. Expects to find
 * stuff on your home./*from  w  w  w  .  j  a v a  2s. c  o  m*/
 */
@Test
public void simpleRawPaged() throws Exception {
    Later<Paged<Object>> feed = this.authBatcher.graph("me/home", new TypeReference<Paged<Object>>() {
    });

    assert !feed.get().getData().isEmpty();
    assert feed.get().getPaging() != null;
}

From source file:org.mayocat.shop.billing.store.jdbi.mapper.OrderMapper.java

@Override
public Order map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException {
    Order order = new Order();
    fillOrderSummary(resultSet, order);/*from   w w w.j a va  2 s . co m*/

    ObjectMapper mapper = new ObjectMapper();
    //mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    try {
        List<Map<String, Object>> itemsData = mapper.readValue(resultSet.getString("items"),
                new TypeReference<List<Map<String, Object>>>() {
                });

        List<OrderItem> items = FluentIterable.from(itemsData)
                .transform(new Function<Map<String, Object>, OrderItem>() {
                    public OrderItem apply(Map<String, Object> map) {
                        OrderItem orderItem = new OrderItem();
                        orderItem.setId(UUID.fromString((String) map.get("id")));
                        orderItem.setOrderId(UUID.fromString((String) map.get("order_id")));
                        if (map.containsKey("purchasable_id") && map.get("purchasable_id") != null) {
                            // There might not be a purchasable id
                            orderItem.setPurchasableId(UUID.fromString((String) map.get("purchasable_id")));
                        }
                        orderItem.setType((String) map.get("type"));
                        orderItem.setTitle((String) map.get("title"));
                        orderItem.setMerchant((String) map.get("merchant"));
                        orderItem.setQuantity(((Integer) map.get("quantity")).longValue());
                        orderItem.setUnitPrice(BigDecimal.valueOf((Double) map.get("unit_price")));
                        orderItem.setItemTotal(BigDecimal.valueOf((Double) map.get("item_total")));
                        if (map.containsKey("vat_rate") && map.get("vat_rate") != null) {
                            // There might not be a VAT rate
                            orderItem.setVatRate(BigDecimal.valueOf((Double) map.get("vat_rate")));
                        }
                        if (map.containsKey("data") && map.get("data") != null) {
                            // There might not be data
                            orderItem.addData((Map<String, Object>) map.get("data"));
                        }
                        return orderItem;
                    }
                }).toList();
        order.setOrderItems(items);
    } catch (IOException e) {
        logger.error("Failed to deserialize order data", e);
    }

    try {
        resultSet.findColumn("email");
        Customer customer = new Customer();
        customer.setId(order.getCustomerId());
        customer.setSlug(resultSet.getString("customer_slug"));
        customer.setEmail(resultSet.getString("email"));
        customer.setFirstName(resultSet.getString("first_name"));
        customer.setLastName(resultSet.getString("last_name"));
        customer.setPhoneNumber(resultSet.getString("phone_number"));
        order.setCustomer(customer);
    } catch (SQLException e) {
        // Nevermind
    }

    try {
        if (resultSet.getObject("billing_address_id") != null) {
            resultSet.findColumn("billing_address_full_name");
            Address billing = new Address();
            billing.setId((UUID) resultSet.getObject("billing_address_id"));
            billing.setFullName(resultSet.getString("billing_address_full_name"));
            billing.setStreet(resultSet.getString("billing_address_street"));
            billing.setStreetComplement(resultSet.getString("billing_address_street_complement"));
            billing.setZip(resultSet.getString("billing_address_zip"));
            billing.setCity(resultSet.getString("billing_address_city"));
            billing.setCountry(resultSet.getString("billing_address_country"));
            billing.setNote(resultSet.getString("billing_address_note"));
            order.setBillingAddress(billing);
        }
    } catch (SQLException e) {
        // Nevermind
    }

    try {
        if (resultSet.getObject("delivery_address_id") != null) {
            resultSet.findColumn("delivery_address_full_name");
            Address delivery = new Address();
            delivery.setId((UUID) resultSet.getObject("delivery_address_id"));
            delivery.setFullName(resultSet.getString("delivery_address_full_name"));
            delivery.setStreet(resultSet.getString("delivery_address_street"));
            delivery.setStreetComplement(resultSet.getString("delivery_address_street_complement"));
            delivery.setZip(resultSet.getString("delivery_address_zip"));
            delivery.setCity(resultSet.getString("delivery_address_city"));
            delivery.setCountry(resultSet.getString("delivery_address_country"));
            delivery.setNote(resultSet.getString("delivery_address_note"));
            order.setDeliveryAddress(delivery);
        }
    } catch (SQLException e) {
        // Nevermind
    }

    return order;
}

From source file:com.spotify.helios.system.LabelTest.java

/**
 * @param hosts Hostnames for which to get labels.
 * @return a map whose keys are hostnames and values are maps of label key-vals.
 *//*from   w w  w  .  j  a  v  a  2 s  . c  o  m*/
private Callable<Map<String, Map<String, String>>> hostLabels(final Set<String> hosts) {
    return () -> {
        final ImmutableMap.Builder<String, Map<String, String>> hostLabels = ImmutableMap.builder();

        for (final String host : hosts) {
            final Map<String, HostStatus> status = Json.read(cli("hosts", host, "--json"),
                    new TypeReference<Map<String, HostStatus>>() {
                    });

            final HostStatus hostStatus = status.get(host);
            if (hostStatus == null) {
                return null;
            }

            final Map<String, String> labels = hostStatus.getLabels();
            if (labels != null && !labels.isEmpty()) {
                hostLabels.put(host, labels);
            } else {
                return null;
            }

        }
        return hostLabels.build();
    };
}

From source file:com.ranger.hazelcast.servicediscovery.RangerServiceDiscoveryHelper.java

public static void start(final String zkConnectionString, final String namespace, final String serviceName,
        final String hostname, final int port, final ILogger logger) throws Exception {
    if (serviceProvider == null) {
        serviceProvider = ServiceProviderBuilders.unshardedServiceProviderBuilder()
                .withConnectionString(zkConnectionString).withNamespace(namespace).withServiceName(serviceName)
                .withSerializer(serviceNode -> {
                    try {
                        return objectMapper.writeValueAsBytes(serviceNode);
                    } catch (JsonProcessingException e) {
                        logger.severe("Cannot serialize data: " + serviceNode.representation(), e);
                    }/*from  w  w  w. j  a  v a2  s .  c o m*/
                    return null;
                }).withHostname(hostname).withPort(port).withHealthcheck(() -> HealthcheckStatus.healthy)
                .buildServiceDiscovery();
        serviceProvider.start();
    }
    if (serviceFinder == null) {
        serviceFinder = ServiceFinderBuilders.unshardedFinderBuilder().withConnectionString(zkConnectionString)
                .withNamespace(namespace).withServiceName(serviceName).withDeserializer(data -> {
                    try {
                        return objectMapper.readValue(data,
                                new TypeReference<ServiceNode<UnshardedClusterInfo>>() {
                                });
                    } catch (IOException e) {
                        logger.severe("Error staring service discovery!", e);
                    }
                    return null;
                }).build();
        serviceFinder.start();
    }
}

From source file:de.tobiasbruns.content.storage.ContentService.java

public Map<String, Object> readJsonData(String path) {
    try {/*from   w w  w. j  av  a 2 s . c om*/
        File file = fsService.getFile(path);

        if (file.isFile()) {
            return objectMapper.readValue(file, new TypeReference<Map<String, Object>>() {
            });
        }
        return readFolder(file);
    } catch (IOException e) {
        throw new RuntimeException("Error when reading json data", e);
    }
}