Search in sources :

Example 1 with ReturnAllBeanProperties

use of org.alfresco.rest.framework.jacksonextensions.JacksonHelper.ReturnAllBeanProperties in project alfresco-remote-api by Alfresco.

the class JsonJacksonTests method testSerializeMultipleObjects.

@Test
public void testSerializeMultipleObjects() throws IOException {
    final Collection<Comment> allComments = new ArrayList<Comment>();
    Comment aComment = new Comment();
    aComment.setContent("<b>There it is</b>");
    allComments.add(aComment);
    aComment = new Comment();
    aComment.setContent("<p>I agree with the author</p>");
    allComments.add(aComment);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    jsonHelper.withWriter(out, new Writer() {

        @Override
        public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
            FilterProvider fp = new SimpleFilterProvider().addFilter(JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
            objectMapper.writer(fp).writeValue(generator, allComments);
        }
    });
    assertTrue(out.toString().contains("content\":\"<b>There it is</b>"));
    assertTrue(out.toString().contains("content\":\"<p>I agree with the author</p>"));
}
Also used : Comment(org.alfresco.rest.api.model.Comment) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ReturnAllBeanProperties(org.alfresco.rest.framework.jacksonextensions.JacksonHelper.ReturnAllBeanProperties) Writer(org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with ReturnAllBeanProperties

use of org.alfresco.rest.framework.jacksonextensions.JacksonHelper.ReturnAllBeanProperties in project alfresco-remote-api by Alfresco.

the class JsonJacksonTests method testSerializeComment.

@Test
public void testSerializeComment() throws IOException {
    final Comment aComment = new Comment();
    aComment.setContent("<b>There it is</b>");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    jsonHelper.withWriter(out, new Writer() {

        @Override
        public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
            FilterProvider fp = new SimpleFilterProvider().addFilter(JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
            objectMapper.writer(fp).writeValue(generator, aComment);
        }
    });
    assertTrue(out.toString().contains("{\"content\":\"<b>There it is</b>\""));
}
Also used : Comment(org.alfresco.rest.api.model.Comment) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ReturnAllBeanProperties(org.alfresco.rest.framework.jacksonextensions.JacksonHelper.ReturnAllBeanProperties) Writer(org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) Test(org.junit.Test)

Example 3 with ReturnAllBeanProperties

use of org.alfresco.rest.framework.jacksonextensions.JacksonHelper.ReturnAllBeanProperties in project alfresco-remote-api by Alfresco.

the class JsonJacksonTests method testNullInComment.

@Test
public void testNullInComment() throws IOException {
    final Comment aComment = new Comment();
    aComment.setContent(null);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    jsonHelper.withWriter(out, new Writer() {

        @Override
        public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
            FilterProvider fp = new SimpleFilterProvider().addFilter(JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
            objectMapper.writer(fp).writeValue(generator, aComment);
        }
    });
    assertEquals("Null values should not be output.", "{\"canEdit\":false,\"canDelete\":false}", out.toString());
}
Also used : Comment(org.alfresco.rest.api.model.Comment) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ReturnAllBeanProperties(org.alfresco.rest.framework.jacksonextensions.JacksonHelper.ReturnAllBeanProperties) Writer(org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) Test(org.junit.Test)

Aggregations

JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)3 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FilterProvider (com.fasterxml.jackson.databind.ser.FilterProvider)3 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 Comment (org.alfresco.rest.api.model.Comment)3 ReturnAllBeanProperties (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.ReturnAllBeanProperties)3 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1