I've a Spring Boot application with RESTful endpoints that I want to add custom serializers to for joda-time but I can't get the applications default Jackson serailzier to recognize my custom one's.
I created RESTFul endpoints using @RepositoryRestResource
@RepositoryRestResource(collectionResourceRel = "x", path = "x")
public interface XRepository extends PagingAndSortingRepository<X, Long>
{
}
I then have a GET call to return all object X's:
This is my serializer:
@Component
public class JsonDateSerializer extends JsonSerializer<DateTime>
{
private static DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy");
@Override
public void serialize(DateTime value, JsonGenerator gen,
SerializerProvider arg2)
throws IOException, JsonProcessingException {
gen.writeString(formatter.print(value));
}
}
And I add it to the property Getter as follows:
@JsonSerialize(using=JsonDateSerializer.class)
public DateTime getDateCreated()
{
return dateCreated;
}
This serializer works perfectly in a normal application but when I try to use this in my Spring Boot application these serializers get ignored.
How can I get Spring Boot to recognize these serializers?