org.codehaus.jackson.map.JsonSerializer Java Examples

The following examples show how to use org.codehaus.jackson.map.JsonSerializer. 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: Jackson1Parser.java    From typescript-generator with MIT License 6 votes vote down vote up
private BeanHelper getBeanHelper(Class<?> beanClass) {
    if (beanClass == null) {
        return null;
    }
    try {
        final SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
        final JavaType simpleType = objectMapper.constructType(beanClass);
        final JsonSerializer<?> jsonSerializer = BeanSerializerFactory.instance.createSerializer(serializationConfig, simpleType, null);
        if (jsonSerializer == null) {
            return null;
        }
        if (jsonSerializer instanceof BeanSerializer) {
            return new BeanHelper((BeanSerializer) jsonSerializer);
        } else {
            final String jsonSerializerName = jsonSerializer.getClass().getName();
            throw new RuntimeException(String.format("Unknown serializer '%s' for class '%s'", jsonSerializerName, beanClass));
        }
    } catch (JsonMappingException e) {
        throw new RuntimeException(e);
    }
}
 
Example #2
Source File: CustomObjectMapper.java    From jeecg with Apache License 2.0 6 votes vote down vote up
public CustomObjectMapper() {
	CustomSerializerFactory factory = new CustomSerializerFactory();
	factory.addGenericMapping(Date.class, new JsonSerializer<Date>() {
		@Override
		public void serialize(Date value, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException, JsonProcessingException {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String dateStr = sdf.format(value);
			if (dateStr.endsWith(" 00:00:00")) {
				dateStr = dateStr.substring(0, 10);
			} else if (dateStr.endsWith(":00")) {
				dateStr = dateStr.substring(0, 16);
			}
			jsonGenerator.writeString(dateStr);
		}
	});
	this.setSerializerFactory(factory);
}
 
Example #3
Source File: JacksonObjectMapperProvider.java    From Bats with Apache License 2.0 4 votes vote down vote up
public <T> void addSerializer(Class<T> clazz, JsonSerializer<T> serializer)
{
  module.addSerializer(clazz, serializer);
}
 
Example #4
Source File: JacksonObjectMapperProvider.java    From Bats with Apache License 2.0 4 votes vote down vote up
public <T> void addSerializer(JsonSerializer<T> serializer)
{
  module.addSerializer(serializer);
}
 
Example #5
Source File: JacksonObjectMapperProvider.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
public <T> void addSerializer(Class<T> clazz, JsonSerializer<T> serializer)
{
  module.addSerializer(clazz, serializer);
}
 
Example #6
Source File: JacksonObjectMapperProvider.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
public <T> void addSerializer(JsonSerializer<T> serializer)
{
  module.addSerializer(serializer);
}
 
Example #7
Source File: JsonTopologySerializer.java    From libcrunch with Apache License 2.0 4 votes vote down vote up
public IsFailedWriter(BeanPropertyWriter base, JsonSerializer<Object> ser) {
  super(base, ser);
}
 
Example #8
Source File: JsonTopologySerializer.java    From libcrunch with Apache License 2.0 4 votes vote down vote up
@Override
public BeanPropertyWriter withSerializer(JsonSerializer<Object> ser) {
  return new IsFailedWriter(this, ser);
}