[JBoss] Alternative for adding a StringConverter when migrating to Resteasy 3

Discussão em 'StackOverflow' iniciado por Stack, Agosto 31, 2021.

  1. Stack

    Stack Membro Participativo

    I am migrating a client to use Resteasy 3. In the previous version I have been using addStringConverter for adding a custom converter to the ReaseasyProviderFactory, but this method is not longer accesible due is protected with the new resteasy version.

    The custom converted implements StringConverter, which is also deprecated. I have created a ParamConverterProvider

    @Provider
    public class DateConverterProvider implements ParamConverterProvider {

    @Override
    public <T> ParamConverter<T> getConverter(Class<T> rawType, Type type, Annotation[] annotations) {
    if (rawType.equals(Date.class)) {
    return (ParamConverter<T>) new DateConverter();
    }
    return null;
    }
    }


    And its related ParamConverter

    public class DateConverter implements ParamConverter<Date> {

    @Override
    public Date fromString(String s) {
    return new Date(Long.parseLong(s));
    }

    @Override
    public String toString(Date date) {
    return String.valueOf(date.getTime());
    }

    }


    And finally adding the ParamConvertedProvider to the factory with .registerProviderInstance(new DateConverterProvider()) But when I use the implementation I got an exception because It can not convert the string value (a date in millis: 123123452343) to Date, so seems it is no getting the converter.

    javax.ws.rs.ProcessingException: RESTEASY008200: JSON Binding deserialization error: javax.json.bind.JsonbException: Unable to deserialize property 'bookingDetail' because of: Unable to deserialize property 'bookingBasicInfo' because of: Unable to deserialize property 'creationDate' because of: Error parsing class java.util.Date from value: 1613098316000. Check your @JsonbDateFormat has all time units for class java.util.Date type, or consider using org.eclipse.yasson.YassonProperties#ZERO_TIME_PARSE_DEFAULTING.

    Continue reading...

Compartilhe esta Página