Package com.fasterxml.jackson.databind

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


    public void testWithGetterAsSetter() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setPropertyNamingStrategy(new CStyleStrategy());
        SetterlessWithValue input = new SetterlessWithValue().add(3);
        String json = mapper.writeValueAsString(input);
        assertEquals("{\"value_list\":[{\"int_value\":3}]}", json);

        SetterlessWithValue result = mapper.readValue(json, SetterlessWithValue.class);
        assertNotNull(result.values);
        assertEquals(1, result.values.size());
View Full Code Here


    public void testPerClassAnnotation() throws Exception
    {
        final ObjectMapper mapper = new ObjectMapper();
        mapper.setPropertyNamingStrategy(new LcStrategy());
        BeanWithPrefixNames input = new BeanWithPrefixNames();
        String json = mapper.writeValueAsString(input);
        assertEquals("{\"Get-a\":3}", json);

        BeanWithPrefixNames output = mapper.readValue("{\"Set-a\":7}",
                BeanWithPrefixNames.class);
        assertEquals(7, output.a);
View Full Code Here

     */

    public void testSharedNames() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        assertEquals("{\"x\":6}", mapper.writeValueAsString(new SharedName(6)));
    }

    public void testSharedNamesFromGetterToSetter() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
View Full Code Here

    }

    public void testSharedNamesFromGetterToSetter() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(new SharedName2());
        assertEquals("{\"x\":1}", json);
        SharedName2 result = mapper.readValue(json, SharedName2.class);
        assertNotNull(result);
    }
   
View Full Code Here

    }
   
    public void testSharedTypeInfo() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(new Wrapper(13L));
        Wrapper result = mapper.readValue(json, Wrapper.class);
        assertEquals(Long.class, result.value.getClass());
    }

    public void testSharedTypeInfoWithCtor() throws Exception
View Full Code Here

    }

    public void testSharedTypeInfoWithCtor() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(new TypeWrapper(13L));
        TypeWrapper result = mapper.readValue(json, TypeWrapper.class);
        assertEquals(Long.class, result.value.getClass());
    }
}
View Full Code Here

        Person1 p1 = new Person1("John");
        p1.setAccount(new Key<Account>(new Account("something", 42L)));
       
        // First: ensure we can serialize (pre 1.7 this failed)
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(p1);

        // and then verify that results make sense
        Map<String,Object> map = mapper.readValue(json, Map.class);
        assertEquals("John", map.get("name"));
        Object ob = map.get("account");
View Full Code Here

        accounts.add(new Key<Account>(new Account("c", 44L)));
        p2.setAccounts(accounts);

        // serialize without error:
        ObjectMapper mapper = new ObjectMapper();              
        String json = mapper.writeValueAsString(p2);

        // then verify output
        Map<String,Object> map = mapper.readValue(json, Map.class);
        assertEquals("John", map.get("name"));
        Object ob = map.get("accounts");
View Full Code Here

      if (outputConfig.isDebug()) {
        configObjectString = mapper.writerWithDefaultPrettyPrinter()
            .writeValueAsString(modelObject);
      }
      else {
        configObjectString = mapper.writeValueAsString(modelObject);
      }

    }
    catch (JsonGenerationException e) {
      throw new RuntimeException(e);
View Full Code Here

      if (config.isDebug()) {
        configObjectString = mapper.writerWithDefaultPrettyPrinter()
            .writeValueAsString(modelObject);
      }
      else {
        configObjectString = mapper.writeValueAsString(modelObject);
      }

    }
    catch (JsonGenerationException e) {
      throw new RuntimeException(e);
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.