org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion Java Examples

The following examples show how to use org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WriteJsonServletHandler.java    From urule with Apache License 2.0 6 votes vote down vote up
protected void writeObjectToJson(HttpServletResponse resp,Object obj) throws ServletException, IOException{
	resp.setHeader("Access-Control-Allow-Origin", "*");
	resp.setContentType("text/json");
	resp.setCharacterEncoding("UTF-8");
	ObjectMapper mapper=new ObjectMapper();
	mapper.setSerializationInclusion(Inclusion.NON_NULL);
	mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,false);
	mapper.setDateFormat(new SimpleDateFormat(Configure.getDateFormat()));
	OutputStream out = resp.getOutputStream();
	try {
		mapper.writeValue(out, obj);
	} finally {
		out.flush();
		out.close();
	}
}
 
Example #2
Source File: Json.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
public static String toJson(Object object) {
	ObjectMapper mapper = new ObjectMapper(new MyJsonFactory());
	SimpleModule module = new SimpleModule("fullcalendar", new Version(1, 0, 0, null));
	module.addSerializer(new DateTimeSerializer());
	module.addSerializer(new LocalTimeSerializer());
	mapper.registerModule(module);
	mapper.getSerializationConfig().setSerializationInclusion(Inclusion.NON_NULL);

	String json = null;
	try {
		json = mapper.writeValueAsString(object);
	} catch (Exception e) {
		throw new RuntimeException("Error encoding object: " + object + " into JSON string", e);
	}
	return json;
}
 
Example #3
Source File: WriteJsonServletHandler.java    From uflo with Apache License 2.0 6 votes vote down vote up
protected void writeObjectToJson(HttpServletResponse resp,Object obj) throws ServletException, IOException{
	resp.setHeader("Access-Control-Allow-Origin", "*");
	resp.setContentType("text/json");
	resp.setCharacterEncoding("UTF-8");
	ObjectMapper mapper=new ObjectMapper();
	mapper.setSerializationInclusion(Inclusion.NON_NULL);
	mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,false);
	mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
	OutputStream out = resp.getOutputStream();
	try {
		mapper.writeValue(out, obj);
	} finally {
		out.flush();
		out.close();
	}
}
 
Example #4
Source File: RedisPublisher.java    From onboard with Apache License 2.0 6 votes vote down vote up
private void broadcastByActivity(User owner, Activity activity, BaseProjectItem originalItem, BaseProjectItem updatedItem)
        throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.getSerializationConfig().setSerializationInclusion(Inclusion.NON_NULL);
    ObjectWriter ow = objectMapper.writer().withDefaultPrettyPrinter();
    activity.setSubscribers(userService.getUserByProjectId(activity.getProjectId()));
    activity.setAttachObject((BaseProjectItem)identifiableManager.getIdentifiableByTypeAndId(activity.getAttachType(),
            activity.getAttachId()));
    String message = "";
    try {
        message = ow.writeValueAsString(activity);
    } catch (IOException e) {
        e.printStackTrace();
    }
    template.convertAndSend("channel", message);
}
 
Example #5
Source File: ObjectMapperResolver.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public ObjectMapperResolver() throws Exception {
    mapper = new ObjectMapper();

    final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector();
    final SerializationConfig serializationConfig = mapper.getSerializationConfig();
    final DeserializationConfig deserializationConfig = mapper.getDeserializationConfig();

    mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector));
    mapper.setDeserializationConfig(deserializationConfig.withAnnotationIntrospector(jaxbIntrospector));
}
 
Example #6
Source File: AbstractEntity.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public String getName() {
    Object value = getProperty( PROPERTY_NAME );

    if ( value instanceof UUID ) {
        // fixes existing data that uses UUID in USERGRID-2099
        return value.toString();
    }

    return ( String ) value;
}
 
Example #7
Source File: ObjectMapperResolver.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public ObjectMapperResolver() throws Exception {
    mapper = new ObjectMapper();

    final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector();
    final SerializationConfig serializationConfig = mapper.getSerializationConfig();
    final DeserializationConfig deserializationConfig = mapper.getDeserializationConfig();

    mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector));
    mapper.setDeserializationConfig(deserializationConfig.withAnnotationIntrospector(jaxbIntrospector));
}
 
Example #8
Source File: JSONRPCEncoder.java    From bitcoin-transaction-explorer with MIT License 5 votes vote down vote up
public static String getRequestStringWithParameters(final String method, final ArrayList<Object> parameters) throws JsonGenerationException, JsonMappingException, IOException {
  final JSONRPCRequest req = new JSONRPCRequest(method);
  req.setParams(parameters);

  final StringWriter writer = new StringWriter();

  final ObjectMapper mapper = new ObjectMapper();
  mapper.setSerializationInclusion(Inclusion.NON_EMPTY);
  mapper.writeValue(writer, req);

  return writer.toString();
}
 
Example #9
Source File: WebSocketServiceImpl.java    From onboard with Apache License 2.0 5 votes vote down vote up
/**
 * 根据map生成json
 * 
 * @param actionMap
 * @return
 */
private String getJson(Object activity) {
    ObjectMapper objectMapper = new ObjectMapper();

    objectMapper.getSerializationConfig().setSerializationInclusion(Inclusion.NON_NULL);
    ObjectWriter ow = objectMapper.writer().withDefaultPrettyPrinter();
    String message = "";
    try {
        message = ow.writeValueAsString(activity);
    } catch (IOException e) {
        logger.info("activity to json failure");
    }
    return message;
}
 
Example #10
Source File: WriteJsonServletAction.java    From ureport with Apache License 2.0 5 votes vote down vote up
protected void writeObjectToJson(HttpServletResponse resp,Object obj) throws ServletException, IOException{
	resp.setContentType("text/json");
	resp.setCharacterEncoding("UTF-8");
	ObjectMapper mapper=new ObjectMapper();
	mapper.setSerializationInclusion(Inclusion.NON_NULL);
	mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,false);
	mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
	OutputStream out = resp.getOutputStream();
	try {
		mapper.writeValue(out, obj);
	} finally {
		out.flush();
		out.close();
	}
}
 
Example #11
Source File: JacksonSupportJson.java    From howsun-javaee-framework with Apache License 2.0 5 votes vote down vote up
public JacksonSupportJson(Inclusion inclusion) {
	objectMapper = new ObjectMapper();
	//设置输出包含的属性
	objectMapper.getSerializationConfig().setSerializationInclusion(inclusion);
	//设置输入时忽略JSON字符串中存在而Java对象实际没有的属性
	objectMapper.getDeserializationConfig().set(
			org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	setDateFormat(null);
}
 
Example #12
Source File: ObjectMapperResolver.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public ObjectMapperResolver() throws Exception {
    mapper = new ObjectMapper();

    final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector();
    final SerializationConfig serializationConfig = mapper.getSerializationConfig();
    final DeserializationConfig deserializationConfig = mapper.getDeserializationConfig();

    mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector));
    mapper.setDeserializationConfig(deserializationConfig.withAnnotationIntrospector(jaxbIntrospector));
}
 
Example #13
Source File: AggregateCounterSet.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public UUID getQueue() {
    return queue;
}
 
Example #14
Source File: AggregateCounterSet.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public List<AggregateCounter> getValues() {
    return values;
}
 
Example #15
Source File: AggregateCounterSet.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public String getName() {
    return name;
}
 
Example #16
Source File: AggregateCounterSet.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public String getCategory() {
    return category;
}
 
Example #17
Source File: AbstractEntity.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
@EntityProperty(indexed = true, required = true, mutable = false)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public Long getCreated() {
    return created;
}
 
Example #18
Source File: AggregateCounterSet.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public UUID getGroup() {
    return group;
}
 
Example #19
Source File: AggregateCounterSet.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public UUID getUser() {
    return user;
}
 
Example #20
Source File: AbstractEntity.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public Object getMetadata( String key ) {
    return getDataset( "metadata", key );
}
 
Example #21
Source File: AbstractEntity.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
@EntityProperty(indexed = true, required = true, mutable = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public Long getModified() {
    return modified;
}
 
Example #22
Source File: AbstractEntity.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
@EntityProperty(required = true, mutable = false, basic = true, indexed = false)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public UUID getUuid() {
    return uuid;
}
 
Example #23
Source File: BulkV2Connection.java    From components with Apache License 2.0 4 votes vote down vote up
static String serializeToJson(Object value) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(Inclusion.NON_NULL);
    mapper.setDateFormat(CalendarCodec.getDateFormat());
    return mapper.writeValueAsString(value);
}
 
Example #24
Source File: YarnJacksonJaxbJsonProvider.java    From big-c with Apache License 2.0 4 votes vote down vote up
public static void configObjectMapper(ObjectMapper mapper) {
  AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
  mapper.setAnnotationIntrospector(introspector);
  mapper.setSerializationInclusion(Inclusion.NON_NULL);
}
 
Example #25
Source File: YarnJacksonJaxbJsonProvider.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public static void configObjectMapper(ObjectMapper mapper) {
  AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
  mapper.setAnnotationIntrospector(introspector);
  mapper.setSerializationInclusion(Inclusion.NON_NULL);
}
 
Example #26
Source File: JacksonSupportJson.java    From howsun-javaee-framework with Apache License 2.0 2 votes vote down vote up
/**
 * 创建输出全部属性到Json字符串的Binder.
 * @return Json
 */
public static Json buildNormalBinder() {
	return new JacksonSupportJson(Inclusion.ALWAYS);
}
 
Example #27
Source File: JacksonSupportJson.java    From howsun-javaee-framework with Apache License 2.0 2 votes vote down vote up
/**
 * 创建只输出非空属性到Json字符串的Binder.
 * @return Json
 */
public static Json buildNonNullBinder() {
	return new JacksonSupportJson(Inclusion.NON_NULL);
}
 
Example #28
Source File: JacksonSupportJson.java    From howsun-javaee-framework with Apache License 2.0 2 votes vote down vote up
/**
 * 创建只输出初始值被改变的属性到Json字符串的Binder.
 * @return Json
 */
public static Json buildNonDefaultBinder() {
	return new JacksonSupportJson(Inclusion.NON_DEFAULT);
}