List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference
protected TypeReference()
From source file:javaslang.jackson.datatype.PolymorphicTypesTest.java
@Test public void deserializeMap() throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new JavaslangModule()); Map<String, I> i = mapper.readerFor(new TypeReference<Map<String, I>>() { }).readValue("{\"a\":{\"type\":\"a\"},\"b\":{\"type\":\"b\"}}"); Assert.assertTrue(i.nonEmpty());// ww w.ja v a 2 s . c o m Assert.assertTrue(i.get("a").get() instanceof A); Assert.assertTrue(i.get("b").get() instanceof B); }
From source file:com.github.philippn.yqltables.tests.YahooFinanceComponentsTest.java
@Test public void testDaxLowerCase() throws Exception { YqlQueryBuilder builder = YqlQueryBuilder.fromQueryString( "use '" + TABLE_DEFINTION + "' as mytable; select * from mytable where symbol=@symbol"); builder.withVariable("symbol", "^gdaxi"); YqlResult result = client.query(builder.build()); String[] components = result.getContentAsMappedObject(new TypeReference<QueryResultType<String[]>>() { }).getResults();/*w ww. j av a 2s .c om*/ assertEquals(30, components.length); assertTrue(asList(components).contains("ALV.DE")); }
From source file:com.servioticy.api.commons.data.Group.java
/** Create a Group from a JsonNode document. * * @param root The JsonNode Root/*from www . ja va 2 s . co m*/ */ public Group(final JsonNode root) { try { // Check if exist stream if (root.path("stream").isMissingNode()) throw new ServIoTWebApplicationException(Response.Status.NOT_FOUND, "The stream field was not found"); // Check if exist soIds if (root.path("soIds").isMissingNode()) throw new ServIoTWebApplicationException(Response.Status.NOT_FOUND, "The soIds field was not found"); streamId = ((ObjectNode) root).get("stream").asText(); try { soIds = mapper.readValue(mapper.writeValueAsString(root.get("soIds")), new TypeReference<ArrayList<String>>() { }); } catch (JsonProcessingException e) { throw new ServIoTWebApplicationException(Response.Status.BAD_REQUEST, "soIds has to be an array of Strings"); } } catch (JsonProcessingException e) { LOG.error(e); throw new ServIoTWebApplicationException(Response.Status.BAD_REQUEST, e.getMessage()); } catch (IOException e) { LOG.error(e); throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage()); } }
From source file:org.mayocat.shop.billing.store.jdbi.mapper.AbstractOrderMapper.java
protected void fillOrderSummary(ResultSet resultSet, OrderSummary order) throws SQLException { order.setId((UUID) resultSet.getObject("id")); order.setSlug(resultSet.getString("slug")); order.setBillingAddressId((UUID) resultSet.getObject("billing_address_id")); order.setDeliveryAddressId((UUID) resultSet.getObject("delivery_address_id")); order.setCustomerId((UUID) resultSet.getObject("customer_id")); order.setCreationDate(resultSet.getTimestamp("creation_date")); order.setUpdateDate(resultSet.getTimestamp("update_date")); order.setNumberOfItems(resultSet.getLong("number_of_items")); order.setCurrency(Currency.getInstance(resultSet.getString("currency"))); order.setItemsTotal(resultSet.getBigDecimal("items_total")); order.setItemsTotalExcl(resultSet.getBigDecimal("items_total_excl")); order.setShipping(resultSet.getBigDecimal("shipping")); order.setShippingExcl(resultSet.getBigDecimal("shipping_excl")); order.setGrandTotal(resultSet.getBigDecimal("grand_total")); order.setGrandTotalExcl(resultSet.getBigDecimal("grand_total_excl")); order.setStatus(OrderSummary.Status.valueOf(resultSet.getString("status"))); order.setAdditionalInformation(resultSet.getString("additional_information")); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new GuavaModule()); try {/*from w ww . j a va2s. c om*/ Map<String, Object> data = mapper.readValue(resultSet.getString("order_data"), new TypeReference<Map<String, Object>>() { }); order.setOrderData(data); } catch (IOException e) { logger.error("Failed to deserialize order data", e); } }
From source file:com.vmware.photon.controller.api.client.resource.VmApi.java
/** * Get details about the specified vm./*from w w w . j ava 2 s . com*/ * @param vmId * @return Vm details * @throws java.io.IOException */ public Vm getVm(String vmId) throws IOException { String path = String.format("%s/%s", getBasePath(), vmId); HttpResponse httpResponse = this.restClient.perform(RestClient.Method.GET, path, null); this.restClient.checkResponse(httpResponse, HttpStatus.SC_OK); return this.restClient.parseHttpResponse(httpResponse, new TypeReference<Vm>() { }); }
From source file:com.skcraft.launcher.creator.util.ModInfoReader.java
/** * Detect the mods listed in the given .jar * * @param file The file/*ww w . ja v a 2s . c o m*/ * @return A list of detected mods */ public List<? extends ModInfo> detectMods(File file) { Closer closer = Closer.create(); try { FileInputStream fis = closer.register(new FileInputStream(file)); BufferedInputStream bis = closer.register(new BufferedInputStream(fis)); ZipInputStream zis = closer.register(new ZipInputStream(bis)); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { if (entry.getName().equalsIgnoreCase(FORGE_INFO_FILENAME)) { List<ForgeModInfo> mods; String content = CharStreams.toString(new InputStreamReader(zis, Charsets.UTF_8)); try { mods = mapper.readValue(content, ForgeModManifest.class).getMods(); } catch (JsonMappingException | JsonParseException e) { mods = mapper.readValue(content, new TypeReference<List<ForgeModInfo>>() { }); } if (mods != null) { // Ignore "examplemod" return Collections.unmodifiableList( mods.stream().filter(info -> !info.getModId().equals("examplemod")) .collect(Collectors.toList())); } else { return Collections.emptyList(); } } else if (entry.getName().equalsIgnoreCase(LITELOADER_INFO_FILENAME)) { String content = CharStreams.toString(new InputStreamReader(zis, Charsets.UTF_8)); return new ImmutableList.Builder<ModInfo>() .add(mapper.readValue(content, LiteLoaderModInfo.class)).build(); } } return Collections.emptyList(); } catch (JsonMappingException e) { log.log(Level.WARNING, "Unknown format " + FORGE_INFO_FILENAME + " file in " + file.getAbsolutePath(), e); return Collections.emptyList(); } catch (JsonParseException e) { log.log(Level.WARNING, "Corrupt " + FORGE_INFO_FILENAME + " file in " + file.getAbsolutePath(), e); return Collections.emptyList(); } catch (IOException e) { log.log(Level.WARNING, "Failed to read " + file.getAbsolutePath(), e); return Collections.emptyList(); } finally { try { closer.close(); } catch (IOException ignored) { } } }
From source file:org.graylog.plugins.beats.BeatsCodec.java
@Nullable @Override/* w ww .ja v a2 s.co m*/ public Message decode(@Nonnull RawMessage rawMessage) { final byte[] payload = rawMessage.getPayload(); final Map<String, Object> event; try { event = objectMapper.readValue(payload, new TypeReference<Map<String, Object>>() { }); } catch (IOException e) { LOG.error("Couldn't decode raw message {}", rawMessage); return null; } return parseEvent(event); }
From source file:com.evrythng.java.wrapper.service.BatchService.java
/** * Retrieves the referenced {@link Batch}. * <p>//from w w w. ja v a 2s . c o m * GET {@value #PATH_BATCH} * * @param batchId batch id * @return a preconfigured {@link Builder} */ public Builder<Batch> batchReader(final String batchId) throws EvrythngClientException { return get(String.format(PATH_BATCH, batchId), new TypeReference<Batch>() { }); }
From source file:com.arkea.jenkins.openstack.heat.build.AbstractStackTest.java
protected boolean testPerform(String taskName, String stackName, Result result, boolean delete, boolean debug, List<String> testLogDebug, String jsonFileTest) { try {/*from ww w. ja va2 s . c om*/ OpenStack4jClient clientOS = Mockito.mock(OpenStack4jClient.class); // Configure the project and the hot file String pathHot = getClass().getResource("/hot/demo-template.yaml").getPath(); ArrayList<HeatStack> stacks = (new ObjectMapper()).readValue( new File(getClass().getResource("/" + jsonFileTest).getPath()), new TypeReference<ArrayList<HeatStack>>() { }); // Create the bundle to test Bundle bundle = new Bundle("demo-template.yaml", stackName, delete, debug); Map<String, Parameter> params = new HashMap<String, Parameter>(); params.put("NetID", new Parameter("NetID", Type.String, "", "", "", false, "NetID")); bundle.setParameters(params); AnswerStack answerStack = new AnswerStack(stacks); // Mock the stack Mockito.when(clientOS.getStackByName(Mockito.anyString())).thenAnswer(answerStack); Mockito.when(clientOS.getDetails(Mockito.anyString(), Mockito.anyString())).thenAnswer(answerStack); // Create Jenkins project FreeStyleProject project = j.createFreeStyleProject(taskName); // Global configuration HOTPlayerSettings hPS = (HOTPlayerSettings) Jenkins.getInstance() .getDescriptor(HOTPlayerSettings.class); // Mock isConnectionOK Mockito.when(clientOS.isConnectionOK()).thenReturn(true); // Mock the create stack Mockito.when(clientOS.createStack(bundle.getName(), pathHot, bundle.getParamsOS(), null, hPS.getTimersOS().getTimeoutProcessInMin())).thenAnswer(answerStack); // Create task HotPlayer HOTPlayer hotPlayer = new HOTPlayer("projectTest", bundle, clientOS); project.getBuildersList().add(hotPlayer); project.save(); // Execute the test FreeStyleBuild build = project.scheduleBuild2(0).get(); if (debug) { String s = FileUtils.readFileToString(build.getLogFile()); for (String test : testLogDebug) { if (!s.contains(test)) { return false; } } } if (result.equals(build.getResult())) { return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:com.vmware.photon.controller.api.client.resource.ResourceTicketApi.java
/** * Get details about the specified resource ticket. * * @param resourceTicketId//from www. ja v a 2 s .c om * @param responseCallback * @throws IOException */ public void getResourceTicketAsync(final String resourceTicketId, final FutureCallback<ResourceTicket> responseCallback) throws IOException { final String path = String.format("%s/%s", getBasePath(), resourceTicketId); getObjectByPathAsync(path, responseCallback, new TypeReference<ResourceTicket>() { }); }