Skip to content

Custom Serializer for java.util.Date not working #65

@ninadtare10

Description

@ninadtare10

I have written custom serializer for java.util.Date, code as follows

public class DateMapper extends JsonSerializer<Date>{

	@Override
	public void serialize(Date dateObje, JsonGenerator jgen, SerializerProvider serializers) throws IOException, JsonProcessingException {
		// TODO Auto-generated method stub
		String formattedDate = new SimpleDateFormat("yyyy-MM-dd").format(dateObje);
        jgen.writeString(formattedDate);
	}
}

And I am trying to register it as follows

@Configuration
public class Mapper extends WebMvcConfigurerAdapter {
	@Bean
	  public JsonViewSupportFactoryBean views() {
		JsonViewSupportFactoryBean bean = new JsonViewSupportFactoryBean();
		bean.registerCustomSerializer(Date.class, new DateMapper());
	    return bean;
	  }
}

But its not working, not sure why.
I have tried the same way for string and its working fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions