List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference
protected TypeReference()
From source file:com.xeiam.xchange.mtgox.v1.service.marketdata.streaming.TickerJSONTest.java
@Test public void testStreamingUnmarshal() throws IOException { // Read in the JSON from the example resources InputStream is = TickerJSONTest.class .getResourceAsStream("/v1/marketdata/streaming/example-ticker-streaming-data.json"); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); Map<String, Object> userInMap = mapper.readValue(is, new TypeReference<Map<String, Object>>() { });/*w w w.j av a 2s . c o m*/ // Use Jackson to parse it mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); MtGoxTicker mtGoxTicker = mapper.readValue(mapper.writeValueAsString(userInMap.get("ticker")), MtGoxTicker.class); // Verify that the example data was unmarshalled correctly assertThat(mtGoxTicker.getBuy().getValue()).isEqualTo(new BigDecimal("90.78469")); assertThat(mtGoxTicker.getNow()).isEqualTo(1364667533416136L); }
From source file:test.com.wealdtech.jackson.modules.JacksonModulesTest.java
@Test public void testDeserSimpleString() throws Exception { final Optional<?> value = this.mapper.readValue("\"simpleString\"", new TypeReference<Optional<String>>() { });/*from w ww. j av a 2 s .c o m*/ assertTrue(value.isPresent()); assertEquals("simpleString", value.get()); }
From source file:com.networknt.light.rule.post.GetPostRule.java
public boolean execute(Object... objects) throws Exception { Map<String, Object> inputMap = (Map<String, Object>) objects[0]; Map<String, Object> data = (Map<String, Object>) inputMap.get("data"); String host = (String) data.get("host"); boolean allowEdit = false; Map<String, Object> payload = (Map<String, Object>) inputMap.get("payload"); if (payload != null) { Map<String, Object> user = (Map<String, Object>) payload.get("user"); List roles = (List) user.get("roles"); if (roles.contains("owner")) { allowEdit = true;// w ww . j a va2s . c o m } else if (roles.contains("admin") || roles.contains("blogAdmin") || roles.contains("blogUser")) { if (host.equals(user.get("host"))) { allowEdit = true; } } } long total = DbService.getCount("Post", data); if (total > 0) { Map<String, Object> result = new HashMap<String, Object>(); result.put("total", total); String posts = DbService.getData("Post", data); List<Map<String, Object>> jsonList = mapper.readValue(posts, new TypeReference<List<HashMap<String, Object>>>() { }); result.put("posts", jsonList); result.put("allowEdit", allowEdit); inputMap.put("result", mapper.writeValueAsString(result)); return true; } else { inputMap.put("result", "No post can be found."); inputMap.put("responseCode", 404); return false; } }
From source file:org.springframework.social.linkedin.api.impl.CompanyTemplate.java
public List<Company> getCompaniesByEmailDomain(String domain) { String[] params = new String[] { "", "email-domain=" + domain }; JsonNode node = restOperations.getForObject(expand(COMPANY_URL, params, false), JsonNode.class); try {//w w w.j a va2 s . c o m return objectMapper.reader(new TypeReference<List<Company>>() { }).readValue(node.path("values")); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.meltmedia.dropwizard.etcd.json.KeyHeartbeatsIT.java
@SuppressWarnings("unchecked") @Before//from w w w . j a va 2s . c o m public void setUp() { handler = mock(EtcdEventHandler.class); EtcdJson.MappedEtcdDirectory<NodeData> directory = factoryRule.getFactory().newDirectory("/nodes", new TypeReference<NodeData>() { }); heartbeats = directory.newHeartbeat("/id", new NodeData().withName("id"), 1); watch = directory.registerWatch(handler); }
From source file:org.mayocat.shop.shipping.store.jdbi.mapper.CarrierMapper.java
@Override public Carrier map(int index, ResultSet r, StatementContext ctx) throws SQLException { Carrier carrier = null;/*from w w w .j av a 2 s .c om*/ UUID thisRowId = (UUID) r.getObject("id"); if (ctx.getAttribute("__accumulator") != null) { carrier = (Carrier) ctx.getAttribute("__accumulator"); if (!carrier.getId().equals(thisRowId)) { carrier = new Carrier(); } } if (carrier == null) { carrier = new Carrier(); } carrier.setId(thisRowId); carrier.setTitle(r.getString("title")); carrier.setDescription(r.getString("description")); carrier.setId((UUID) r.getObject("id")); carrier.setTenantId((UUID) r.getObject("tenant_id")); carrier.setMinimumDays(r.getInt("minimum_days")); carrier.setMaximumDays(r.getInt("maximum_days")); carrier.setStrategy(Strategy.fromJson(r.getString("strategy"))); carrier.setPerShipping(r.getBigDecimal("per_shipping")); carrier.setPerItem(r.getBigDecimal("per_item")); carrier.setPerAdditionalUnit(r.getBigDecimal("per_additional_unit")); ObjectMapper objectMapper = new ObjectMapper(); try { carrier.setDestinations(objectMapper.<List<String>>readValue(r.getString("destinations"), new TypeReference<List<String>>() { })); } catch (IOException e) { throw new SQLException("Failed to de-serialize carrier destinations", e); } if (r.getBigDecimal("price") != null) { CarrierRule rule = new CarrierRule(); rule.setUpToValue(r.getBigDecimal("up_to_value")); rule.setPrice(r.getBigDecimal("price")); carrier.addRule(rule); } if (r.getBigDecimal("vat_rate") != null) { carrier.setVatRate(r.getBigDecimal("vat_rate")); } ctx.setAttribute("__accumulator", carrier); return carrier; }
From source file:org.apache.drill.exec.store.couchbase.CouchbaseStoragePlugin.java
@Override public CouchbaseGroupScan getPhysicalScan(JSONOptions selection) throws IOException { CouchbaseScanSpec scanSpec = selection.getListWith(new ObjectMapper(), new TypeReference<CouchbaseScanSpec>() { });//from w ww. java 2s. c o m return new CouchbaseGroupScan(this, scanSpec.bucket); }
From source file:org.springframework.security.jackson2.UserDeserializer.java
/** * This method will create {@link User} object. It will ensure successful object creation even if password key is null in * serialized json, because credentials may be removed from the {@link User} by invoking {@link User#eraseCredentials()}. * In that case there won't be any password key in serialized json. *///from ww w .j a v a 2 s . com @Override public User deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectMapper mapper = (ObjectMapper) jp.getCodec(); JsonNode jsonNode = mapper.readTree(jp); Set<GrantedAuthority> authorities = mapper.convertValue(jsonNode.get("authorities"), new TypeReference<Set<SimpleGrantedAuthority>>() { }); return new User(readJsonNode(jsonNode, "username").asText(), readJsonNode(jsonNode, "password").asText(), readJsonNode(jsonNode, "enabled").asBoolean(), readJsonNode(jsonNode, "accountNonExpired").asBoolean(), readJsonNode(jsonNode, "credentialsNonExpired").asBoolean(), readJsonNode(jsonNode, "accountNonLocked").asBoolean(), authorities); }
From source file:org.mayocat.shop.marketplace.store.jdbi.AbstractEntityAndTenantMapper.java
@Override public EntityAndTenant<Product> map(int index, ResultSet result, StatementContext ctx) throws SQLException { Product product = extractEntity(index, result, ctx); String slug = result.getString("tenant_entity_slug"); String defaultHost = result.getString("tenant_entity_default_host"); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new GuavaModule()); Integer configurationVersion = result.getInt("tenant_entity_configuration_version"); TenantConfiguration configuration;//from w ww.j ava2s . com if (Strings.isNullOrEmpty(result.getString("tenant_entity_configuration"))) { configuration = new TenantConfiguration(configurationVersion, Collections.<String, Serializable>emptyMap()); } else { try { Map<String, Serializable> data = mapper.readValue(result.getString("tenant_entity_configuration"), new TypeReference<Map<String, Object>>() { }); configuration = new TenantConfiguration(configurationVersion, data); } catch (IOException e) { final Logger logger = LoggerFactory.getLogger(TenantMapper.class); logger.error("Failed to load configuration for tenant with slug [{}]", e); configuration = new TenantConfiguration(); } } Tenant tenant = new Tenant((UUID) result.getObject("tenant_entity_id"), slug, configuration); tenant.setFeaturedImageId((UUID) result.getObject("tenant_entity_featured_image_id")); tenant.setSlug(slug); tenant.setDefaultHost(defaultHost); tenant.setCreationDate(result.getTimestamp("tenant_entity_creation_date")); tenant.setName(result.getString("tenant_entity_name")); tenant.setDescription(result.getString("tenant_entity_description")); tenant.setContactEmail(result.getString("tenant_entity_contact_email")); return new EntityAndTenant<>(product, tenant); }
From source file:com.evrythng.java.wrapper.service.AuthService.java
/** * Register a new {@link User} in the system. * <p>/* w ww . ja va2s .c o m*/ * POST {@value #PATH_AUTH_EVRYTHNG_USERS} * * @param user {@link User} instance * @return a preconfigured {@link Builder} */ public Builder<Credentials> evrythngUserCreator(final User user) throws EvrythngClientException { return post(PATH_AUTH_EVRYTHNG_USERS, user, new TypeReference<Credentials>() { }); }