Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ninadtare10 opened this issue Mar 5, 2019 · 0 comments
Open

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

ninadtare10 opened this issue Mar 5, 2019 · 0 comments

Comments

@ninadtare10
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant