Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.ObjectMapper.reader()


    public void testUnwrappingSubWithAttribute()
        throws Exception
    {
        final String XML = "<UnwrappingSubWithAttributes name=\"Joe\" loc.x=\"15\"><loc.y>27</loc.y></UnwrappingSubWithAttributes>";
        ObjectMapper mapper = xmlMapper(false);
        UnwrappingSubWithAttributes wrapper = mapper.reader(UnwrappingSubWithAttributes.class).readValue(XML);
        assertNotNull(wrapper);
        assertNotNull(wrapper.location);
        assertEquals(15, wrapper.location.x);
        assertEquals(27, wrapper.location.y);
View Full Code Here


    public void testSimpleViaObjectReader() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        XmlMapper xmlMapper = new XmlMapper();

        ObjectReader detecting = mapper.reader(POJO.class);
        detecting = detecting
                .withFormatDetection(detecting, xmlMapper.reader(POJO.class));
        POJO pojo = detecting.readValue(utf8Bytes("<POJO><y>3</y><x>1</x></POJO>"));
        assertNotNull(pojo);
        assertEquals(1, pojo.x);
View Full Code Here

        ListPOJO list = new ListPOJO();
        list.v.add(new POJO(1, 2));
        list.v.add(new POJO(3, 4));
        String xml = xmlMapper.writeValueAsString(list);

        ObjectReader detecting = mapper.reader(ListPOJO.class);
        ListPOJO resultList = detecting
                .withFormatDetection(detecting, xmlMapper.reader(ListPOJO.class))
                .readValue(utf8Bytes(xml));
        assertNotNull(resultList);
        assertEquals(2, resultList.v.size());
View Full Code Here

      return (String)executeScript("return JSON.stringify(JSON.decycle(function(arguments){"+ script + "}(arguments)));", params);
    }   
   
    private <T> T deserializeJsonAs(Class<T> classOfT, final String objString){
      ObjectMapper mapper = getMapper();
      ObjectReader reader = mapper.reader(classOfT);
      if (inject != null){
        reader = reader.with(inject);
      }
      try {
        return reader.readValue(objString);
View Full Code Here

    }
    }
   
    private <T> List<T> deserializeJsonAsListOf(Class<T> classOfT, final String objString){
      ObjectMapper mapper = getMapper();
      ObjectReader reader = mapper.reader(TypeFactory.defaultInstance().constructCollectionType(List.class, classOfT));
      if (inject != null){
        reader = reader.with(inject);
      }
      try {
        return reader.readValue(objString);
View Full Code Here

    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new FacebookModule());
    jp.setCodec(mapper);
    if(jp.hasCurrentToken()) {
      JsonNode dataNode = (JsonNode) jp.readValueAs(JsonNode.class).get("data");
      return (List<Tag>) mapper.reader(new TypeReference<List<Tag>>() {}).readValue(dataNode);
    }
   
    return null;
  }
}
View Full Code Here

    mapper.registerModule(new FacebookModule());
    jp.setCodec(mapper);
    if (jp.hasCurrentToken()) {
      JsonNode dataNode = jp.readValueAs(JsonNode.class);
      if (dataNode != null) {
        return (Map<Integer,List<MessageTag>>) mapper.reader(new TypeReference<Map<Integer,List<MessageTag>>>() {}).readValue(dataNode);
      }
    }
   
    return Collections.emptyMap();
  }
View Full Code Here

    mapper.registerModule(new FacebookModule());
    jp.setCodec(mapper);
    if (jp.hasCurrentToken()) {
      JsonNode dataNode = (JsonNode) jp.readValueAs(JsonNode.class).get("data");
      if (dataNode != null) {
        return (List<Reference>) mapper.reader(new TypeReference<List<Reference>>() {}).readValue(dataNode);
      }
    }
   
    return Collections.emptyList();
  }
View Full Code Here

  public void readBSONFile() throws Exception {
    InputStream is = getClass().getResourceAsStream("test.bson");
    try {
      ObjectMapper mapper = new ObjectMapper(new BsonFactory());
      MappingIterator<BSONObject> iterator =
          mapper.reader(BasicBSONObject.class).readValues(is);

      BSONObject o = null;
      while (iterator.hasNext()) {
        assertNull(o);
        BSONObject object = iterator.next();
View Full Code Here

        String admin = objectMapper.writer().writeValueAsString(
                new StdUser("admin", ImmutableSet.<String>of("restx-admin")));

        assertThat(admin).isEqualTo("{\"name\":\"admin\",\"roles\":[\"restx-admin\"]}");

        StdUser u = objectMapper.reader().withType(StdUser.class).readValue(admin);
        assertThat(u.getName()).isEqualTo("admin");
        assertThat(u.getPrincipalRoles()).isEqualTo(ImmutableSet.<String>of("restx-admin"));

    }
}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.