mapper.getSerializationConfig().setAnnotationIntrospector(new JacksonAnnotationIntrospector());
mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
jsonFactory.setCodec(mapper);
StringWriter writer = new StringWriter();
JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer);
jsonGenerator.useDefaultPrettyPrinter();
jsonGenerator.writeObject(object);
return writer.getBuffer().toString();
}
}