Package com.fasterxml.jackson.databind.type

Examples of com.fasterxml.jackson.databind.type.CollectionType


        }
    }

    public <T> ImmutableList<T> read(InputStream is, Class<T> elementClass) {
        try {
            CollectionType type = factory.constructCollectionType(List.class, elementClass);
            List<T> sessionSettings = mapper.readValue(new InputStreamReader(is, Charset.defaultCharset()), type);
            return copyOf(sessionSettings);
        } catch (UnrecognizedPropertyException e) {
            logger.info("Unrecognized field: {}", e.getMessage());
            throw new RuntimeException(format("Unrecognized field [ %s ], please check!", e.getPropertyName()));
View Full Code Here


        final List<MyDto> listOfDtos = Lists.newArrayList(new MyDto("a", 1, true), new MyDto("bc", 3, false));
        final String jsonArray = mapper.writeValueAsString(listOfDtos);
        // [{"stringValue":"a","intValue":1,"booleanValue":true},{"stringValue":"bc","intValue":3,"booleanValue":false}]

        final CollectionType javaType = mapper.getTypeFactory().constructCollectionType(List.class, MyDto.class);
        final List<MyDto> asList = mapper.readValue(jsonArray, javaType);
        assertThat(asList.get(0), instanceOf(MyDto.class));
    }
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  private <T> List<T> deserializeDataList(JsonNode jsonNode, final Class<T> elementType) {
    try {
      CollectionType listType = TypeFactory.defaultInstance().constructCollectionType(List.class, elementType);
      return (List<T>) objectMapper.reader(listType).readValue(jsonNode.toString()); // TODO: EXTREMELY HACKY--TEMPORARY UNTIL I FIGURE OUT HOW JACKSON 2 DOES THIS
    } catch (IOException e) {
      throw new UncategorizedApiException("facebook", "Error deserializing data from Facebook: " + e.getMessage(), e);
    }
  }
View Full Code Here

        try (final HttpResponse response = this.client.executeWithLoadBalancer(request)) {
            if (response.isSuccess()) {
                LOG.debug("Response returned success.");
                final ObjectMapper mapper = new ObjectMapper();
                if (collectionClass != null) {
                    final CollectionType type = mapper.
                            getTypeFactory().
                            constructCollectionType(collectionClass, entityClass);
                    return mapper.readValue(response.getInputStream(), type);
                } else {
                    return mapper.readValue(response.getInputStream(), entityClass);
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.databind.type.CollectionType

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.