Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.ObjectMapper


        if (webResponse.getStatusCode() != HttpStatus.SC_OK) {
            throw new IOException(String.format("Error getting access token: [%s: %s]",
                webResponse.getStatusCode(), webResponse.getStatusMessage()));
        }
        final long currentTime = System.currentTimeMillis();
        final ObjectMapper mapper = new ObjectMapper();
        final Map map = mapper.readValue(webResponse.getContentAsStream(), Map.class);
        final String accessToken = map.get("access_token").toString();
        final Integer expiresIn = Integer.valueOf(map.get("expires_in").toString());
        return new OAuthToken(refreshToken, accessToken,
            currentTime + TimeUnit.MILLISECONDS.convert(expiresIn, TimeUnit.SECONDS));
    }
View Full Code Here


            conn.disconnect();

            User user = new User();
            user = user.getUserFromSession(session());

            ObjectMapper mapper = new ObjectMapper();
            String pretty = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode);

            return ok(views.html.community.index.render(user, communities, "Top Level Communities", pretty, endpoint));

        } catch (MalformedURLException e) {
            Logger.error(e.getMessage(), e);
View Full Code Here

        }

        restResponse.httpResponse = httpResponse;
        restResponse.endpoint = request.getURI().toString();

        ObjectMapper mapper = new ObjectMapper();
        String pretty = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(collection);
        restResponse.jsonString = pretty;

        restResponse.modelObject = collection;

        return restResponse;
View Full Code Here

            }

            JsonNode comm = Json.parse(contentString.toString());
            restResponse.endpoint = conn.getURL().toString();

            ObjectMapper mapper = new ObjectMapper();
            String pretty = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(comm);
            restResponse.jsonString = pretty;

            if (comm.size() > 0) {
                Community community = Community.parseCommunityFromJSON(comm);
                restResponse.modelObject = community;
View Full Code Here

  }

  protected void readMappings() throws IOException, JsonParseException,
      JsonMappingException {
    // Read mapping out of JSON file
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory factory = new JsonFactory();
    InputStream is = this.getClass().getResourceAsStream(MAPPING_FILE);
    JsonParser jp = factory.createParser(is);

    jp.nextToken();
    mappings.clear();
    while (jp.nextToken() == JsonToken.START_OBJECT) {
      URLMapping mapping = mapper.readValue(jp, URLMapping.class);
      mappings.add(mapping);
    }
  }
View Full Code Here

  public JacksonSerializer() {
    this(new InclusiveAnnotationIntrospector());
  }

  public JacksonSerializer(AnnotationIntrospector introspector) {
    mapper = new ObjectMapper();
    mapper.setAnnotationIntrospector(introspector);
  }
View Full Code Here

    packages.add("org.platformlayer.xaas.web.jaxrs");
    packages.add("org.platformlayer.xaas.web.resources");
    // packages.add("org.codehaus.jackson.jaxrs");

    TypeFactory typeFactory = TypeFactory.defaultInstance();
    ObjectMapper objectMapper = JsonHelper.buildObjectMapper(typeFactory, false);

    // TypeResolverBuilder<?> typer = new PlatformLayerTypeResolverBuilder();
    // TypeIdResolver typeIdResolver = new PlatformLayerTypeIdResolver(null, typeFactory);
    // this.requestInjection(typeIdResolver);
    // typer = typer.init(JsonTypeInfo.Id.CLASS, typeIdResolver);
View Full Code Here

public class ObjectMapperFactory {
    private static ObjectMapper mapper;

    public static ObjectMapper getInstance() {
        if (mapper == null) {
            mapper = new ObjectMapper();
            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
            mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
            mapper.registerModule(new JodaModule());
        }
View Full Code Here

    {
      String resourceName = key + ".json";
      try {
        String json = ResourceUtils.find(contextClass, resourceName);
        if (json != null) {
          ObjectMapper mapper = new ObjectMapper();

          // Use JAXB annotations
          AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
          mapper = mapper.setAnnotationIntrospector(introspector);

          mapper = mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
          mapper = mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
          mapper = mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);

          if (!json.startsWith("{")) {
            // Be tolerant
            json = "{ " + json + "}";
            // json = jsonHelper.wrapJson(json);
          }

          return mapper.readValue(json, clazz);
          // return jsonHelper.unmarshal(json);
        }
      } catch (Exception e) {
        throw new OpsException("Error reading resource: " + resourceName, e);
      }
View Full Code Here

        assertThat(payload, not(containsString("alert")));

    }

    private void assertEqualsJson(final String expected, final String actual) {
        final ObjectMapper mapper = new ObjectMapper();
        try {
            @SuppressWarnings("unchecked")
            final
            Map<String, Object> exNode = mapper.readValue(expected, Map.class),
                 acNode = mapper.readValue(actual, Map.class);
            assertEquals(exNode, acNode);
        } catch (final Exception e) {
            throw new IllegalStateException(e);
        }
    }
View Full Code Here

TOP

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

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.