Q:

@JsonSerialize with generics

I have the following code to Serialize LocalDate of joda to a String:
public class JodaDateSerializer extends JsonSerializer<ReadablePartial> {
    private static final String dateFormat = ("yyyy-MM-dd");
    @Override
    public void serialize(ReadablePartial date, JsonGenerator gen, SerializerProvider provider)
            throws IOException, JsonProcessingException {

        String formattedDate = DateTimeFormat.forPattern(dateFormat).print(date);

        gen.writeString(formattedDate);
    }
}

and I use it like this:
@JsonSerialize(using = JodaDateSerializer.class)
LocalDate sentDate;

I would like to pass the dateformat pattern e.g. (yyyy-MM-dd) to the class when I declare it. 
I thought to use generics something like this:
JodaDateSerializer<T>

T String;

But I am not sure how to use it where I declare the sendDate variable:
@JsonSerialize(using = JodaDateSerializer<???>.class)
LocalDate sentDate;

Any help? 

A:

If you use jackson json parser.  you can not pass addition parameter to JsonSerialize annotation nor pass generic parameter to  JsonSerializer class.  
I think the only way is create a new JsonSerializer sub class for every date format like this:
public abstract class JodaDateSerializer extends JsonSerializer<ReadablePartial> {

    protected abstract String getDateFormat();

    @Override
    public void serialize(ReadablePartial date, JsonGenerator gen, SerializerProvider provider)
            throws IOException, JsonProcessingException {

        String formattedDate = DateTimeFormat.forPattern(getDateFormat()).print(date);

        gen.writeString(formattedDate);
    }
}

public class LocalDateSerializer extends JodaDateSerializer {

    protected String getDateFormat(){
        return "yyyy-MM-dd";
    }

}

public class OtherDateSerializer extends JodaDateSerializer {

    protected String getDateFormat(){
        return "yyyy/MM/dd";
    }

}

Then use the roper DateSerializer class for your field. 
@JsonSerialize(using = LocalDateSerializer.class)
LocalDate sentDate;

@JsonSerialize(using = OtherDateSerializer.class)
OtherDate otherDate;

