Package com.fasterxml.jackson.databind

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


   
    // [JACKSON-764]
    public void testRootUsingExplicitConfig() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        ObjectWriter writer = mapper.writer().withRootName("wrapper");
        String json = writer.writeValueAsString(new Bean());
        assertEquals("{\"wrapper\":{\"a\":3}}", json);

        ObjectReader reader = mapper.reader(Bean.class).withRootName("wrapper");
        Bean bean = reader.readValue(json);
View Full Code Here


        Bean bean = reader.readValue(json);
        assertNotNull(bean);

        // also: verify that we can override SerializationFeature as well:
        ObjectMapper wrapping = rootMapper();
        json = wrapping.writer().withRootName("something").writeValueAsString(new Bean());
        assertEquals("{\"something\":{\"a\":3}}", json);
        json = wrapping.writer().withRootName("").writeValueAsString(new Bean());
        assertEquals("{\"a\":3}", json);

        bean = wrapping.reader(Bean.class).withRootName("").readValue(json);
View Full Code Here

        // also: verify that we can override SerializationFeature as well:
        ObjectMapper wrapping = rootMapper();
        json = wrapping.writer().withRootName("something").writeValueAsString(new Bean());
        assertEquals("{\"something\":{\"a\":3}}", json);
        json = wrapping.writer().withRootName("").writeValueAsString(new Bean());
        assertEquals("{\"a\":3}", json);

        bean = wrapping.reader(Bean.class).withRootName("").readValue(json);
        assertNotNull(bean);
    }
View Full Code Here

    public void testMapperVersions()
    {
        ObjectMapper mapper = new ObjectMapper();
        assertVersion(mapper);
        assertVersion(mapper.reader());
        assertVersion(mapper.writer());
        assertVersion(new JacksonAnnotationIntrospector());
    }

    /*
    /**********************************************************
 
View Full Code Here

  @Before
  public void init()
  {
    ObjectMapper mapper = new ObjectMapper();
    writer = mapper.writer();
    serialized = new StringWriter();
  }

  @Test
  public void testGreaterThanInt() throws IOException
View Full Code Here

    final boolean isSmile = APPLICATION_SMILE.equals(req.getContentType());

    ObjectMapper objectMapper = isSmile ? smileMapper : jsonMapper;
    final ObjectWriter jsonWriter = req.getParameter("pretty") == null
                                    ? objectMapper.writer()
                                    : objectMapper.writerWithDefaultPrettyPrinter();

    try {
      requestQuery = ByteStreams.toByteArray(req.getInputStream());
      query = objectMapper.readValue(requestQuery, Query.class);
View Full Code Here

    resp.setContentType("application/json");
    ObjectMapper om = new ObjectMapper();
    try
    {
      ObjectWriter writer = om.writer().withType(om.constructType(getClass().getMethod("prototype").getGenericReturnType()));
      writer.writeValue(resp.getOutputStream(), Lists.newArrayList(one, two, three));
    }
    catch (Exception e)
    {
      throw new ServletException(e);
View Full Code Here

    }

    private ObjectWriter getWriterForView(Class<?> view) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
        return mapper.writer().withView(view);
    }
   
}
View Full Code Here

       
        mapper.addMixInAnnotations(Object.class, IgnoreTypeMixIn.class);
       
        final FilterProvider filters = new SimpleFilterProvider().addFilter("storedDataFilter", SimpleBeanPropertyFilter.serializeAllExcept("storedData"));

        final ObjectWriter ssWriter = mapper.writer(filters);
        final ObjectReader ssReader = mapper.reader(sus.getClass());
       
        final String susString = ssWriter.writeValueAsString(sus);
        System.out.println(susString);
        final StorelessUnivariateStatistic newSus = ssReader.readValue(susString);
View Full Code Here

        ObjectMapper mapper = new ObjectMapper();
        mapper.findAndRegisterModules();
       
        mapper.addMixInAnnotations(Object.class, PortletRenderExecutionEventFilterMixIn.class);
        final FilterProvider filterProvider = new SimpleFilterProvider().addFilter(PortletRenderExecutionEventFilterMixIn.FILTER_NAME, SimpleBeanPropertyFilter.filterOutAllExcept("fname", "executionTimeNano", "parameters"));
        final ObjectWriter portletEventWriter = mapper.writer(filterProvider);
       
        final String result = portletEventWriter.writeValueAsString(createEvent());
       
        assertEquals("{\"@c\":\".PortletRenderExecutionEvent\",\"fname\":\"fname1\",\"executionTimeNano\":123450000,\"parameters\":{}}", result);
    }
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.