List of usage examples for com.fasterxml.jackson.core.type TypeReference TypeReference
protected TypeReference()
From source file:com.netflix.suro.routing.TestRoutingMap.java
private Map<String, RoutingInfo> getRoutingMap(String desc) throws Exception { return injector.getInstance(ObjectMapper.class).<Map<String, RoutingInfo>>readValue(desc, new TypeReference<Map<String, RoutingInfo>>() { });/*from w w w .j a v a2s .com*/ }
From source file:com.xeiam.xchange.mtgox.v2.service.marketdata.polling.streaming.TickerJSONTest.java
@Test public void testStreamingUnmarshal() throws IOException { // Read in the JSON from the example resources InputStream is = TickerJSONTest.class .getResourceAsStream("/v2/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>>() { });/*from ww w . jav 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:com.mapr.synth.samplers.SchemaSampler.java
public SchemaSampler(String schemaDefinition) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); init(mapper.<List<FieldSampler>>readValue(schemaDefinition, new TypeReference<List<FieldSampler>>() { }));//from w w w.j av a 2 s .c om }
From source file:plugins.marauders.MaraudersDELETEServlet.java
@Override public HttpResponse handleRequest(HttpRequest request) { String body = new String(request.getBody()); ObjectMapper mapper = new ObjectMapper(); TypeReference<HashMap<String, Object>> typeReference = new TypeReference<HashMap<String, Object>>() { };/*from w ww . j a va 2 s . co m*/ try { HashMap<String, Object> map = mapper.readValue(body, typeReference); String nameObj = (String) map.get("name"); String passphraseObj = (String) map.get("passphrase"); Data d = MaraudersInteractor.getData(); boolean okPassphrase = passphraseObj.equals(d.passphrase); if (okPassphrase) { boolean b = MaraudersInteractor.deleteStudent(nameObj); if (b) { HttpResponse res = HttpResponseFactory.createDelete(Protocol.CLOSE); return res; } else { return HttpResponseFactory.create304NotModified(Protocol.CLOSE); } } else { Random rand = new Random(); int id = rand.nextInt(d.maxInsultID + 1); try { Insult i = MaraudersInteractor.getInsult(id + ""); File f = File.createTempFile("temp", ".txt"); FileOutputStream fos = new FileOutputStream(f); fos.write((i.toString()).getBytes()); fos.flush(); fos.close(); HttpResponse res = HttpResponseFactory.create394Insult(f, Protocol.CLOSE); //f.delete(); return res; } catch (Exception e) { e.printStackTrace(); return HttpResponseFactory.create400BadRequest(Protocol.CLOSE); } } } catch (Exception e) { e.printStackTrace(); } return HttpResponseFactory.create400BadRequest(Protocol.CLOSE); }
From source file:com.vmware.photon.controller.api.client.resource.ClusterRestApi.java
/** * Get details about the specified cluster. * * @param clusterId/* w w w. j a v a 2s. c o m*/ * @return * @throws IOException */ @Override public Cluster getCluster(String clusterId) throws IOException { String path = String.format("%s/%s", getBasePath(), clusterId); HttpResponse httpResponse = this.restClient.perform(RestClient.Method.GET, path, null); this.restClient.checkResponse(httpResponse, HttpStatus.SC_OK); return this.restClient.parseHttpResponse(httpResponse, new TypeReference<Cluster>() { }); }
From source file:com.basistech.rosette.dm.json.plain.NameTest.java
@Test public void name() throws Exception { List<Name> names = Lists.newArrayList(); Name.Builder builder = new Name.Builder("Fred"); names.add(builder.build());/*from w w w. ja v a2s . c om*/ builder = new Name.Builder("George"); builder.languageOfOrigin(LanguageCode.ENGLISH).script(ISO15924.Latn).languageOfUse(LanguageCode.FRENCH); names.add(builder.build()); ObjectMapper mapper = objectMapper(); String json = mapper.writeValueAsString(names); // one way to inspect the works is to read it back in _without_ our customized mapper. ObjectMapper plainMapper = new ObjectMapper(); JsonNode tree = plainMapper.readTree(json); assertTrue(tree.isArray()); assertEquals(2, tree.size()); JsonNode node = tree.get(0); assertTrue(node.has("text")); assertEquals("Fred", node.get("text").asText()); assertFalse(node.has("script")); assertFalse(node.has("languageOfOrigin")); assertFalse(node.has("languageOfUse")); List<Name> readBack = mapper.readValue(json, new TypeReference<List<Name>>() { }); assertEquals(names, readBack); }
From source file:org.springframework.social.linkedin.api.impl.JobTemplate.java
public Jobs searchJobs(JobSearchParameters parameters) { Object[] params = new Object[] { parameters.getKeywords(), parameters.getCompanyName(), parameters.getJobTitle(), parameters.getCountryCode(), parameters.getPostalCode(), parameters.getDistance(), parameters.getStart(), parameters.getCount(), parameters.getSort() }; JsonNode node = restOperations.getForObject(expand(SEARCH_URL, params, true), JsonNode.class); try {/*from www .j a va 2 s . c om*/ return objectMapper.reader(new TypeReference<Jobs>() { }).readValue(node.path("jobs")); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:plugins.marauders.MaraudersPOSTServlet.java
@Override public HttpResponse handleRequest(HttpRequest request) { String body = new String(request.getBody()); ObjectMapper mapper = new ObjectMapper(); TypeReference<HashMap<String, Object>> typeReference = new TypeReference<HashMap<String, Object>>() { };//from w w w .j a va2 s . co m try { HashMap<String, Object> map = mapper.readValue(body, typeReference); String nameObj = (String) map.get("name"); String passphraseObj = (String) map.get("passphrase"); String locationObj = (String) map.get("location"); Data d = MaraudersInteractor.getData(); boolean okPassphrase = passphraseObj.equals(d.passphrase); if (okPassphrase) { boolean b = MaraudersInteractor.updateStudentLocation(nameObj, locationObj); if (b) { Student s = MaraudersInteractor.getStudent(nameObj); s.setLocation(locationObj); try { File f = File.createTempFile("temp", ".txt"); FileOutputStream fos = new FileOutputStream(f); fos.write((s.toString()).getBytes()); fos.flush(); fos.close(); Thread.sleep(100); HttpResponse res = HttpResponseFactory.create200OK(f, Protocol.CLOSE); return res; } catch (Exception e) { e.printStackTrace(); return HttpResponseFactory.create400BadRequest(Protocol.CLOSE); } } } else { Random rand = new Random(); int id = rand.nextInt(d.maxInsultID + 1); try { Insult i = MaraudersInteractor.getInsult(id + ""); File f = File.createTempFile("temp", ".txt"); FileOutputStream fos = new FileOutputStream(f); fos.write((i.toString()).getBytes()); fos.flush(); fos.close(); HttpResponse res = HttpResponseFactory.create394Insult(f, Protocol.CLOSE); //f.delete(); return res; } catch (Exception e) { e.printStackTrace(); return HttpResponseFactory.create400BadRequest(Protocol.CLOSE); } } } catch (Exception e) { e.printStackTrace(); } return HttpResponseFactory.create400BadRequest(Protocol.CLOSE); }
From source file:com.github.nmorel.gwtjackson.guava.jackson.ImmutablesJacksonTest.java
@Test public void testImmutableSortedSet() { ImmutablesTester.INSTANCE//from w w w . j av a2 s . c o m .testImmutableSortedSet(createMapper(new TypeReference<ImmutableSortedSet<Integer>>() { })); }
From source file:com.vmware.photon.controller.client.resource.DeploymentApi.java
/** * Lists all deployments.//from w ww .j a v a2 s .c o m * * @param responseCallback * @throws IOException */ public void listAllAsync(final FutureCallback<ResourceList<Deployment>> responseCallback) throws IOException { getObjectByPathAsync(getBasePath(), responseCallback, new TypeReference<ResourceList<Deployment>>() { }); }