You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by "Thiago Henrique De Paula Figueiredo (Jira)" <ji...@apache.org> on 2021/10/07 14:22:00 UTC

[jira] [Closed] (TAP5-2695) Create convenience methods for contributing coercions

     [ https://issues.apache.org/jira/browse/TAP5-2695?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thiago Henrique De Paula Figueiredo closed TAP5-2695.
-----------------------------------------------------
    Fix Version/s: 5.8.0
       Resolution: Fixed

Two static methods were added to CoercionTuple:
 * add(
 MappedConfiguration<CoercionTuple.Key, CoercionTuple> configuration, 
 Class<S> sourceType, Class<T> targetType, Coercion<S, T> coercion)
 * override(
 MappedConfiguration<CoercionTuple.Key, CoercionTuple> configuration, 
 Class<S> sourceType, Class<T> targetType, Coercion<S, T> coercion)

So now you can contribute coercions like this example taken from Tapestry itself:
{code:java}
    public static void contributeTypeCoercer(MappedConfiguration<CoercionTuple.Key, CoercionTuple> configuration)
    {
        CoercionTuple.add(configuration, HttpServletRequest.class, String.class, TapestryHttpModule::toString);
        CoercionTuple.add(configuration, HttpServletRequest.class, byte[].class, TapestryHttpModule::toByteArray);
        CoercionTuple.add(configuration, HttpServletRequest.class, InputStream.class, TapestryHttpModule::toInputStream);
        CoercionTuple.add(configuration, HttpServletRequest.class, Reader.class, TapestryHttpModule::toBufferedReader);
        CoercionTuple.add(configuration, HttpServletRequest.class, BufferedReader.class, TapestryHttpModule::toBufferedReader);
    }

{code}

> Create convenience methods for contributing coercions
> -----------------------------------------------------
>
>                 Key: TAP5-2695
>                 URL: https://issues.apache.org/jira/browse/TAP5-2695
>             Project: Tapestry 5
>          Issue Type: Improvement
>          Components: commons
>            Reporter: Thiago Henrique De Paula Figueiredo
>            Assignee: Thiago Henrique De Paula Figueiredo
>            Priority: Minor
>             Fix For: 5.8.0
>
>
> Since Tapestry 5.7.0, when contributions to TypeCoercer became mapped ones, they got more complicated to do.
> Example of how they were done before: 
> {code:java}
> configuration.add(CoercionTuple.create(sourceType, targetType, coercion));
> {code}
> Example of how they have been done since 5.7.0:
> {code:java}
> CoercionTuple<S, T> tuple = CoercionTuple.create(sourceType, targetType, coercion);
> configuration.add(tuple.getKey(), tuple);
> {code}
> We should create a new method in CoercionTuple so coercion contributions can be again done with a single method call.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)