Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.ObjectReader


    @Test
    public void testContainer() throws IOException {
        final Fixture expected = new Fixture();
        final String str = writer.writeValueAsString(expected);
        Assert.assertTrue(str.contains("DEBUG"));
        final ObjectReader fixtureReader = log4jObjectMapper.reader(Fixture.class);
        final Fixture actual = fixtureReader.readValue(str);
        Assert.assertEquals(expected, actual);
    }
View Full Code Here


 
  @Test
  public void parseSimplePlan() throws Exception{
    DrillConfig c = DrillConfig.create();
    PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
    ObjectReader r = c.getMapper().reader(PhysicalPlan.class);
    ObjectWriter writer = c.getMapper().writer();
    PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/physical_test1.json"), Charsets.UTF_8));
    System.out.println(plan.unparse(writer));
  }
View Full Code Here

        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost tokenPost = new HttpPost(TOKEN_URL);
        tokenPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
        tokenPost.setEntity(new StringEntity(entity, "UTF-8"));
        CloseableHttpResponse resp1 = httpclient.execute(tokenPost);
        ObjectReader jreader = Utils.getJsonReader(Map.class);

        if (resp1 != null && resp1.getEntity() != null) {
          Map<String, Object> token = jreader.readValue(resp1.getEntity().getContent());
          if (token != null && token.containsKey("access_token")) {
            // got valid token
            HttpGet profileGet = new HttpGet(PROFILE_URL);
            profileGet.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token.get("access_token"));
            CloseableHttpResponse resp2 = httpclient.execute(profileGet);
            HttpEntity respEntity = resp2.getEntity();
            String ctype = resp2.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();

            if (respEntity != null && Utils.isJsonType(ctype)) {
              Map<String, Object> profile = jreader.readValue(resp2.getEntity().getContent());

              if (profile != null && profile.containsKey("sub")) {
                String googleSubId = (String) profile.get("sub");
                String pic = (String) profile.get("picture");
                String email = (String) profile.get("email");
View Full Code Here

            request.getRequestURL().toString(), Config.LINKEDIN_APP_ID, Config.LINKEDIN_SECRET);

        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost tokenPost = new HttpPost(url);
        CloseableHttpResponse resp1 = httpclient.execute(tokenPost);
        ObjectReader jreader = Utils.getJsonReader(Map.class);

        if (resp1 != null && resp1.getEntity() != null) {
          Map<String, Object> token = jreader.readValue(resp1.getEntity().getContent());
          if (token != null && token.containsKey("access_token")) {
            // got valid token
            HttpGet profileGet = new HttpGet(PROFILE_URL + token.get("access_token"));
            CloseableHttpResponse resp2 = httpclient.execute(profileGet);
            HttpEntity respEntity = resp2.getEntity();
            String ctype = resp2.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();

            if (respEntity != null && Utils.isJsonType(ctype)) {
              Map<String, Object> profile = jreader.readValue(resp2.getEntity().getContent());

              if (profile != null && profile.containsKey("id")) {
                String linkedInID = (String) profile.get("id");
                String email = (String) profile.get("emailAddress");
                String pic = (String) profile.get("pictureUrl");
View Full Code Here

  @SuppressWarnings("unchecked")
  private Sysprop fetchFxRatesJSON() {
    Map<String, Object> map = new HashMap<String, Object>();
    Sysprop s = new Sysprop();
    ObjectReader reader = Utils.getJsonReader(Map.class);

    try {
      CloseableHttpClient http = HttpClients.createDefault();
      HttpGet httpGet = new HttpGet(SERVICE_URL);
      HttpResponse res = http.execute(httpGet);
      HttpEntity entity = res.getEntity();

      if (entity != null && Utils.isJsonType(entity.getContentType().getValue())) {
        JsonNode jsonNode = reader.readTree(entity.getContent());
        if (jsonNode != null) {
          JsonNode rates = jsonNode.get("rates");
          if (rates != null) {
            map = reader.treeToValue(rates, Map.class);
            s.setId(FXRATES_KEY);
            s.setProperties(map);
//            s.addProperty("fetched", Utils.formatDate("dd MM yyyy HH:mm", Locale.UK));
            dao.create(s);
          }
View Full Code Here

            request.getRequestURL().toString(), Config.FB_APP_ID, Config.FB_SECRET);

        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpGet tokenPost = new HttpGet(url);
        CloseableHttpResponse resp1 = httpclient.execute(tokenPost);
        ObjectReader jreader = Utils.getJsonReader(Map.class);

        if (resp1 != null && resp1.getEntity() != null) {
          String token = EntityUtils.toString(resp1.getEntity(), Config.DEFAULT_ENCODING);
          if (token != null && token.startsWith("access_token")) {
            // got valid token
            String accessToken = token.substring(token.indexOf("=") + 1, token.indexOf("&"));
            HttpGet profileGet = new HttpGet(PROFILE_URL + accessToken);
            CloseableHttpResponse resp2 = httpclient.execute(profileGet);
            HttpEntity respEntity = resp2.getEntity();
            String ctype = resp2.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();

            if (respEntity != null && Utils.isJsonType(ctype)) {
              Map<String, Object> profile = jreader.readValue(resp2.getEntity().getContent());

              if (profile != null && profile.containsKey("id")) {
                String fbId = (String) profile.get("id");
                Map<String, Object> pic = (Map<String, Object>) profile.get("picture");
                String email = (String) profile.get("email");
View Full Code Here

    }

    @Override
    public <T> T fromJSON(String s, Class<T> aClass) {
        try {
            final ObjectReader reader = mapper.reader(aClass);

            return reader.readValue(s);
        } catch (IOException e) {
            throw Exceptions.runtime(e);
        }
    }
View Full Code Here

  @Test
  public void parseSimplePlan() throws Exception{
    DrillConfig c = DrillConfig.create();
    PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
    ObjectReader r = c.getMapper().reader(PhysicalPlan.class);
    ObjectWriter writer = c.getMapper().writer();
    PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/physical_test1.json"), Charsets.UTF_8));
    System.out.println(plan.unparse(writer));
  }
View Full Code Here

    @Override
    public Void call() {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            ObjectReader reader = objectMapper.reader(Map.class);
            MappingIterator<Map<String, Object>> iterator = reader.readValues(getInputStream());

            while (iterator.hasNextValue()) {
                Map<String, Object> entry = iterator.nextValue();

                // monitor the distribution of countries
View Full Code Here

                .build();
        reporter.start(60, TimeUnit.SECONDS);

        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        ObjectReader reader = objectMapper.reader(Map.class);
        MappingIterator<Map<String, Object>> iterator = reader.readValues(getInputStream());

        try {
            while (iterator.hasNextValue()) {
                Map<String, Object> entry = iterator.nextValue();
                if (entry.containsKey("_heartbeat_")) {
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.databind.ObjectReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.