[jira] [Closed] (TAP5-2565) Enum <-> String coercion is not symmetric if enum class overrides toString()
[ https://issues.apache.org/jira/browse/TAP5-2565?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Jochen Kemnade closed TAP5-2565. Resolution: Fixed Backported to 5.4.x branch > Enum <-> String coercion is not symmetric if enum class overrides toString() > > > Key: TAP5-2565 > URL: https://issues.apache.org/jira/browse/TAP5-2565 > Project: Tapestry 5 > Issue Type: Bug >Affects Versions: 5.4.1 >Reporter: Jochen Kemnade >Assignee: Jochen Kemnade > Fix For: 5.5.0, 5.4.2 > > > See TAP5-2496 and TAP5-1331. > If an enum class overrides {{toString()}}, the coercion is not symmetric > because Enum->String uses {{toString()}} and String->Enum uses {{name()}}. > This breaks {{}} when no encoder is specified. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Updated] (TAP5-2565) Enum <-> String coercion is not symmetric if enum class overrides toString()
[ https://issues.apache.org/jira/browse/TAP5-2565?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Jochen Kemnade updated TAP5-2565: - Fix Version/s: 5.4.2 > Enum <-> String coercion is not symmetric if enum class overrides toString() > > > Key: TAP5-2565 > URL: https://issues.apache.org/jira/browse/TAP5-2565 > Project: Tapestry 5 > Issue Type: Bug >Affects Versions: 5.4.1 >Reporter: Jochen Kemnade >Assignee: Jochen Kemnade > Fix For: 5.5.0, 5.4.2 > > > See TAP5-2496 and TAP5-1331. > If an enum class overrides {{toString()}}, the coercion is not symmetric > because Enum->String uses {{toString()}} and String->Enum uses {{name()}}. > This breaks {{}} when no encoder is specified. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Reopened] (TAP5-2565) Enum <-> String coercion is not symmetric if enum class overrides toString()
[ https://issues.apache.org/jira/browse/TAP5-2565?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Jochen Kemnade reopened TAP5-2565: -- Assignee: Jochen Kemnade > Enum <-> String coercion is not symmetric if enum class overrides toString() > > > Key: TAP5-2565 > URL: https://issues.apache.org/jira/browse/TAP5-2565 > Project: Tapestry 5 > Issue Type: Bug >Affects Versions: 5.4.1 >Reporter: Jochen Kemnade >Assignee: Jochen Kemnade > Fix For: 5.5.0, 5.4.2 > > > See TAP5-2496 and TAP5-1331. > If an enum class overrides {{toString()}}, the coercion is not symmetric > because Enum->String uses {{toString()}} and String->Enum uses {{name()}}. > This breaks {{}} when no encoder is specified. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (TAP5-2496) Inconsistent behavior of EnumValueEncoder
[ https://issues.apache.org/jira/browse/TAP5-2496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15513269#comment-15513269 ] ASF subversion and git services commented on TAP5-2496: --- Commit 45eaae528a4e418cecb03e41d47104853e973aa7 in tapestry-5's branch refs/heads/5.4.x from [~jkemnade] [ https://git-wip-us.apache.org/repos/asf?p=tapestry-5.git;h=45eaae5 ] TAP5-2565, TAP5-2496: always use name() when coercing enum values to String > Inconsistent behavior of EnumValueEncoder > -- > > Key: TAP5-2496 > URL: https://issues.apache.org/jira/browse/TAP5-2496 > Project: Tapestry 5 > Issue Type: Bug >Affects Versions: 5.4 >Reporter: Jochen Kemnade >Assignee: Jochen Kemnade > Fix For: 5.4 > > > EnumValueEncoder uses {{java.lang.Enum.name()}} in {{toClient(E)}} but uses > {{typeCoercer.coerce(clientValue, enumType)}} in {{toValue(String > clientValue)}}. > I have a custom coercer in my project and this causes the value encoder to be > unable to decode the client-side value back to a server-side value. > I think we should remove {{EnumValueEncoderFactory}} altogether because > {{TypeCoercedValueEncoderFactory}} should do its job just fine. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
tapestry-5 git commit: TAP5-2565, TAP5-2496: always use name() when coercing enum values to String
Repository: tapestry-5 Updated Branches: refs/heads/5.4.x af1118b5d -> 45eaae528 TAP5-2565, TAP5-2496: always use name() when coercing enum values to String Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/45eaae52 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/45eaae52 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/45eaae52 Branch: refs/heads/5.4.x Commit: 45eaae528a4e418cecb03e41d47104853e973aa7 Parents: af1118b Author: Jochen KemnadeAuthored: Thu Sep 22 12:05:49 2016 +0200 Committer: Jochen Kemnade Committed: Thu Sep 22 15:10:18 2016 +0200 -- .../ioc/internal/services/TypeCoercerImpl.java| 14 ++ .../test/groovy/ioc/specs/TypeCoercerSpec.groovy | 7 ++- .../src/test/java/com/example/Animal.java | 18 ++ 3 files changed, 38 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/45eaae52/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java -- diff --git a/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java b/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java index 2b157b7..23639ba 100644 --- a/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java +++ b/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java @@ -121,6 +121,15 @@ public class TypeCoercerImpl extends LockSupport implements TypeCoercer } }; +private static final Coercion COERCION_ENUM_TO_STRING = new Coercion () +{ +@Override +public String coerce(Enum input) +{ +return input.name(); +} +}; + public TypeCoercerImpl(Collection tuples) { for (CoercionTuple tuple : tuples) @@ -495,6 +504,11 @@ public class TypeCoercerImpl extends LockSupport implements TypeCoercer { tuples = extend(tuples, new CoercionTuple(sourceType, targetType, new StringToEnumCoercion(targetType))); } +else if (Enum.class.isAssignableFrom(sourceType) && targetType == String.class) +{ +// TAP5-2565 +tuples = extend(tuples, new CoercionTuple(sourceType, targetType, COERCION_ENUM_TO_STRING)); +} return tuples; } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/45eaae52/tapestry-ioc/src/test/groovy/ioc/specs/TypeCoercerSpec.groovy -- diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/TypeCoercerSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/TypeCoercerSpec.groovy index 9a388fb..985d0e4 100644 --- a/tapestry-ioc/src/test/groovy/ioc/specs/TypeCoercerSpec.groovy +++ b/tapestry-ioc/src/test/groovy/ioc/specs/TypeCoercerSpec.groovy @@ -5,6 +5,9 @@ import org.apache.tapestry5.ioc.annotations.AnnotationUseContext import org.apache.tapestry5.ioc.services.TypeCoercer import org.apache.tapestry5.ioc.util.TimeInterval import org.apache.tapestry5.plastic.PlasticUtils + +import com.example.Animal; + import spock.lang.Unroll class TypeCoercerSpec extends AbstractSharedRegistrySpecification { @@ -97,7 +100,9 @@ class TypeCoercerSpec extends AbstractSharedRegistrySpecification { "mixin" | AnnotationUseContext | AnnotationUseContext.MIXIN 123 | Object[] | [123] as Object[] [1, 2, 3] | Object[] | [1, 2, 3] as Object[] - +// TAP5-2565 +Animal.DOG| String | 'DOG' +'CAT' | Animal | Animal.CAT inputTypeName = PlasticUtils.toTypeName(input.getClass()) typeName = PlasticUtils.toTypeName(type) http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/45eaae52/tapestry-ioc/src/test/java/com/example/Animal.java -- diff --git a/tapestry-ioc/src/test/java/com/example/Animal.java b/tapestry-ioc/src/test/java/com/example/Animal.java new file mode 100644 index 000..75826ec --- /dev/null +++ b/tapestry-ioc/src/test/java/com/example/Animal.java @@ -0,0 +1,18 @@ +package com.example; + +public enum Animal { + + CAT("Cat"), DOG("Dog"); + + private final String displayName; + + private Animal(String displayName) { +this.displayName = displayName; + } + + @Override + public String toString() { +return displayName; + } + +}
[jira] [Commented] (TAP5-2565) Enum <-> String coercion is not symmetric if enum class overrides toString()
[ https://issues.apache.org/jira/browse/TAP5-2565?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15513112#comment-15513112 ] Artyom Kravchenko commented on TAP5-2565: - Thank you for the quick fix. Would you be able to please backport that to the 5.4 bug fix release? > Enum <-> String coercion is not symmetric if enum class overrides toString() > > > Key: TAP5-2565 > URL: https://issues.apache.org/jira/browse/TAP5-2565 > Project: Tapestry 5 > Issue Type: Bug >Affects Versions: 5.4.1 >Reporter: Jochen Kemnade > Fix For: 5.5.0 > > > See TAP5-2496 and TAP5-1331. > If an enum class overrides {{toString()}}, the coercion is not symmetric > because Enum->String uses {{toString()}} and String->Enum uses {{name()}}. > This breaks {{}} when no encoder is specified. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (TAP5-2565) Enum <-> String coercion is not symmetric if enum class overrides toString()
[ https://issues.apache.org/jira/browse/TAP5-2565?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15512896#comment-15512896 ] Hudson commented on TAP5-2565: -- FAILURE: Integrated in Jenkins build tapestry-trunk-freestyle #1598 (See [https://builds.apache.org/job/tapestry-trunk-freestyle/1598/]) TAP5-2565, TAP5-2496: always use name() when coercing enum values to (jkemnade: rev 7368fdc536d5ddc6c050b05bdbe45fea4d9517e1) * (edit) tapestry-ioc/src/test/groovy/ioc/specs/TypeCoercerSpec.groovy * (add) tapestry-ioc/src/test/java/com/example/Animal.java * (edit) commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java > Enum <-> String coercion is not symmetric if enum class overrides toString() > > > Key: TAP5-2565 > URL: https://issues.apache.org/jira/browse/TAP5-2565 > Project: Tapestry 5 > Issue Type: Bug >Affects Versions: 5.4.1 >Reporter: Jochen Kemnade > Fix For: 5.5.0 > > > See TAP5-2496 and TAP5-1331. > If an enum class overrides {{toString()}}, the coercion is not symmetric > because Enum->String uses {{toString()}} and String->Enum uses {{name()}}. > This breaks {{}} when no encoder is specified. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (TAP5-2496) Inconsistent behavior of EnumValueEncoder
[ https://issues.apache.org/jira/browse/TAP5-2496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15512897#comment-15512897 ] Hudson commented on TAP5-2496: -- FAILURE: Integrated in Jenkins build tapestry-trunk-freestyle #1598 (See [https://builds.apache.org/job/tapestry-trunk-freestyle/1598/]) TAP5-2565, TAP5-2496: always use name() when coercing enum values to (jkemnade: rev 7368fdc536d5ddc6c050b05bdbe45fea4d9517e1) * (edit) tapestry-ioc/src/test/groovy/ioc/specs/TypeCoercerSpec.groovy * (add) tapestry-ioc/src/test/java/com/example/Animal.java * (edit) commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java > Inconsistent behavior of EnumValueEncoder > -- > > Key: TAP5-2496 > URL: https://issues.apache.org/jira/browse/TAP5-2496 > Project: Tapestry 5 > Issue Type: Bug >Affects Versions: 5.4 >Reporter: Jochen Kemnade >Assignee: Jochen Kemnade > Fix For: 5.4 > > > EnumValueEncoder uses {{java.lang.Enum.name()}} in {{toClient(E)}} but uses > {{typeCoercer.coerce(clientValue, enumType)}} in {{toValue(String > clientValue)}}. > I have a custom coercer in my project and this causes the value encoder to be > unable to decode the client-side value back to a server-side value. > I think we should remove {{EnumValueEncoderFactory}} altogether because > {{TypeCoercedValueEncoderFactory}} should do its job just fine. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[2/2] tapestry-5 git commit: upgrade Gradle wrapper
upgrade Gradle wrapper Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/18b54a84 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/18b54a84 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/18b54a84 Branch: refs/heads/master Commit: 18b54a84232718c2c7c13838753f1f91acb9e194 Parents: b3e07f6 Author: Jochen KemnadeAuthored: Thu Sep 22 12:10:20 2016 +0200 Committer: Jochen Kemnade Committed: Thu Sep 22 12:10:20 2016 +0200 -- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.jar| Bin 53324 -> 52928 bytes gradle/wrapper/gradle-wrapper.properties | 4 ++-- gradlew | 5 + gradlew.bat | 6 -- 5 files changed, 8 insertions(+), 9 deletions(-) -- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/18b54a84/build.gradle -- diff --git a/build.gradle b/build.gradle index 68b59ac..da137fd 100755 --- a/build.gradle +++ b/build.gradle @@ -424,7 +424,7 @@ task continuousIntegration { } task wrapper(type: Wrapper) { -gradleVersion = '2.14.1' +gradleVersion = '3.1' description "Regenerates the Gradle Wrapper files" } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/18b54a84/gradle/wrapper/gradle-wrapper.jar -- diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 3baa851..6ffa237 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/18b54a84/gradle/wrapper/gradle-wrapper.properties -- diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2eff010..c558c90 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jul 20 15:08:04 CEST 2016 +#Thu Sep 22 12:09:59 CEST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-bin.zip http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/18b54a84/gradlew -- diff --git a/gradlew b/gradlew index 27309d9..9aa616c 100755 --- a/gradlew +++ b/gradlew @@ -161,4 +161,9 @@ function splitJvmOpts() { eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then + cd "$(dirname "$0")" +fi + exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/18b54a84/gradlew.bat -- diff --git a/gradlew.bat b/gradlew.bat index f6d5974..e95643d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -49,7 +49,6 @@ goto fail @rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line
[1/2] tapestry-5 git commit: Gradle 3 insists that we specify destinations for reports even if they are disabled
Repository: tapestry-5 Updated Branches: refs/heads/master 7368fdc53 -> 18b54a842 Gradle 3 insists that we specify destinations for reports even if they are disabled Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/b3e07f6d Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/b3e07f6d Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/b3e07f6d Branch: refs/heads/master Commit: b3e07f6d3a604b2266905c9888cc0d4f0082d627 Parents: 7368fdc Author: Jochen KemnadeAuthored: Thu Sep 22 12:08:52 2016 +0200 Committer: Jochen Kemnade Committed: Thu Sep 22 12:08:52 2016 +0200 -- build.gradle | 10 -- 1 file changed, 8 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/b3e07f6d/build.gradle -- diff --git a/build.gradle b/build.gradle index c1db6cc..68b59ac 100755 --- a/build.gradle +++ b/build.gradle @@ -399,8 +399,14 @@ task combinedJacocoReport(type:JacocoReport){ enabled = true destination = "$buildDir/reports/jacoco" } - xml.enabled = false - csv.enabled = false + xml { +enabled = false +destination = "unused" + } + csv { +enabled = false +destination = "unused" + } } onlyIf = { true
[jira] [Closed] (TAP5-2565) Enum <-> String coercion is not symmetric if enum class overrides toString()
[ https://issues.apache.org/jira/browse/TAP5-2565?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Jochen Kemnade closed TAP5-2565. Resolution: Fixed Fix Version/s: 5.5.0 > Enum <-> String coercion is not symmetric if enum class overrides toString() > > > Key: TAP5-2565 > URL: https://issues.apache.org/jira/browse/TAP5-2565 > Project: Tapestry 5 > Issue Type: Bug >Affects Versions: 5.4.1 >Reporter: Jochen Kemnade > Fix For: 5.5.0 > > > See TAP5-2496 and TAP5-1331. > If an enum class overrides {{toString()}}, the coercion is not symmetric > because Enum->String uses {{toString()}} and String->Enum uses {{name()}}. > This breaks {{}} when no encoder is specified. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (TAP5-2496) Inconsistent behavior of EnumValueEncoder
[ https://issues.apache.org/jira/browse/TAP5-2496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15512837#comment-15512837 ] ASF subversion and git services commented on TAP5-2496: --- Commit 7368fdc536d5ddc6c050b05bdbe45fea4d9517e1 in tapestry-5's branch refs/heads/master from [~jkemnade] [ https://git-wip-us.apache.org/repos/asf?p=tapestry-5.git;h=7368fdc ] TAP5-2565, TAP5-2496: always use name() when coercing enum values to String > Inconsistent behavior of EnumValueEncoder > -- > > Key: TAP5-2496 > URL: https://issues.apache.org/jira/browse/TAP5-2496 > Project: Tapestry 5 > Issue Type: Bug >Affects Versions: 5.4 >Reporter: Jochen Kemnade >Assignee: Jochen Kemnade > Fix For: 5.4 > > > EnumValueEncoder uses {{java.lang.Enum.name()}} in {{toClient(E)}} but uses > {{typeCoercer.coerce(clientValue, enumType)}} in {{toValue(String > clientValue)}}. > I have a custom coercer in my project and this causes the value encoder to be > unable to decode the client-side value back to a server-side value. > I think we should remove {{EnumValueEncoderFactory}} altogether because > {{TypeCoercedValueEncoderFactory}} should do its job just fine. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (TAP5-2565) Enum <-> String coercion is not symmetric if enum class overrides toString()
[ https://issues.apache.org/jira/browse/TAP5-2565?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15512836#comment-15512836 ] ASF subversion and git services commented on TAP5-2565: --- Commit 7368fdc536d5ddc6c050b05bdbe45fea4d9517e1 in tapestry-5's branch refs/heads/master from [~jkemnade] [ https://git-wip-us.apache.org/repos/asf?p=tapestry-5.git;h=7368fdc ] TAP5-2565, TAP5-2496: always use name() when coercing enum values to String > Enum <-> String coercion is not symmetric if enum class overrides toString() > > > Key: TAP5-2565 > URL: https://issues.apache.org/jira/browse/TAP5-2565 > Project: Tapestry 5 > Issue Type: Bug >Affects Versions: 5.4.1 >Reporter: Jochen Kemnade > Fix For: 5.5.0 > > > See TAP5-2496 and TAP5-1331. > If an enum class overrides {{toString()}}, the coercion is not symmetric > because Enum->String uses {{toString()}} and String->Enum uses {{name()}}. > This breaks {{}} when no encoder is specified. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
tapestry-5 git commit: TAP5-2565, TAP5-2496: always use name() when coercing enum values to String
Repository: tapestry-5 Updated Branches: refs/heads/master a32af3d85 -> 7368fdc53 TAP5-2565, TAP5-2496: always use name() when coercing enum values to String Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/7368fdc5 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/7368fdc5 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/7368fdc5 Branch: refs/heads/master Commit: 7368fdc536d5ddc6c050b05bdbe45fea4d9517e1 Parents: a32af3d Author: Jochen KemnadeAuthored: Thu Sep 22 12:05:49 2016 +0200 Committer: Jochen Kemnade Committed: Thu Sep 22 12:05:49 2016 +0200 -- .../ioc/internal/services/TypeCoercerImpl.java| 5 + .../test/groovy/ioc/specs/TypeCoercerSpec.groovy | 7 ++- .../src/test/java/com/example/Animal.java | 18 ++ 3 files changed, 29 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7368fdc5/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java -- diff --git a/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java b/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java index 2b157b7..c93655d 100644 --- a/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java +++ b/commons/src/main/java/org/apache/tapestry5/ioc/internal/services/TypeCoercerImpl.java @@ -495,6 +495,11 @@ public class TypeCoercerImpl extends LockSupport implements TypeCoercer { tuples = extend(tuples, new CoercionTuple(sourceType, targetType, new StringToEnumCoercion(targetType))); } +else if (Enum.class.isAssignableFrom(sourceType) && targetType == String.class) +{ +// TAP5-2565 +tuples = extend(tuples, new CoercionTuple(sourceType, targetType, (value)->((Enum) value).name())); +} return tuples; } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7368fdc5/tapestry-ioc/src/test/groovy/ioc/specs/TypeCoercerSpec.groovy -- diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/TypeCoercerSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/TypeCoercerSpec.groovy index 9a388fb..985d0e4 100644 --- a/tapestry-ioc/src/test/groovy/ioc/specs/TypeCoercerSpec.groovy +++ b/tapestry-ioc/src/test/groovy/ioc/specs/TypeCoercerSpec.groovy @@ -5,6 +5,9 @@ import org.apache.tapestry5.ioc.annotations.AnnotationUseContext import org.apache.tapestry5.ioc.services.TypeCoercer import org.apache.tapestry5.ioc.util.TimeInterval import org.apache.tapestry5.plastic.PlasticUtils + +import com.example.Animal; + import spock.lang.Unroll class TypeCoercerSpec extends AbstractSharedRegistrySpecification { @@ -97,7 +100,9 @@ class TypeCoercerSpec extends AbstractSharedRegistrySpecification { "mixin" | AnnotationUseContext | AnnotationUseContext.MIXIN 123 | Object[] | [123] as Object[] [1, 2, 3] | Object[] | [1, 2, 3] as Object[] - +// TAP5-2565 +Animal.DOG| String | 'DOG' +'CAT' | Animal | Animal.CAT inputTypeName = PlasticUtils.toTypeName(input.getClass()) typeName = PlasticUtils.toTypeName(type) http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/7368fdc5/tapestry-ioc/src/test/java/com/example/Animal.java -- diff --git a/tapestry-ioc/src/test/java/com/example/Animal.java b/tapestry-ioc/src/test/java/com/example/Animal.java new file mode 100644 index 000..75826ec --- /dev/null +++ b/tapestry-ioc/src/test/java/com/example/Animal.java @@ -0,0 +1,18 @@ +package com.example; + +public enum Animal { + + CAT("Cat"), DOG("Dog"); + + private final String displayName; + + private Animal(String displayName) { +this.displayName = displayName; + } + + @Override + public String toString() { +return displayName; + } + +}
[jira] [Updated] (TAP5-2565) Enum <-> String coercion is not symmetric if enum class overrides toString()
[ https://issues.apache.org/jira/browse/TAP5-2565?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Jochen Kemnade updated TAP5-2565: - Summary: Enum <-> String coercion is not symmetric if enum class overrides toString() (was: Enum <-> String coercion is not symmetric) > Enum <-> String coercion is not symmetric if enum class overrides toString() > > > Key: TAP5-2565 > URL: https://issues.apache.org/jira/browse/TAP5-2565 > Project: Tapestry 5 > Issue Type: Bug >Affects Versions: 5.4.1 >Reporter: Jochen Kemnade > > See TAP5-2496 and TAP5-1331. > If an enum class overrides {{toString()}}, the coercion is not symmetric > because Enum->String uses {{toString()}} and String->Enum uses {{name()}}. > This breaks {{}} when no encoder is specified. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Created] (TAP5-2565) Enum <-> String coercion is not symmetric
Jochen Kemnade created TAP5-2565: Summary: Enum <-> String coercion is not symmetric Key: TAP5-2565 URL: https://issues.apache.org/jira/browse/TAP5-2565 Project: Tapestry 5 Issue Type: Bug Affects Versions: 5.4.1 Reporter: Jochen Kemnade See TAP5-2496 and TAP5-1331. If an enum class overrides {{toString()}}, the coercion is not symmetric because Enum->String uses {{toString()}} and String->Enum uses {{name()}}. This breaks {{}} when no encoder is specified. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (TAP5-2496) Inconsistent behavior of EnumValueEncoder
[ https://issues.apache.org/jira/browse/TAP5-2496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15512569#comment-15512569 ] Artyom Kravchenko commented on TAP5-2496: - Hi I use 5.4.1 version. I see that {code:borderStyle=solid}EnumValueEncoder.toClient(E){code} has {code:borderStyle=solid}typeCoercer.coerce(value, String.class){code} instead of {code:borderStyle=solid}java.lang.Enum.name(){code} as it was in 5.3.8 (my previous version). I did not find any commits (work logs) in this task and 5.4.1 tasks where {code:borderStyle=solid}EnumValueEncoder.toClient(E){code} was changed. But any way it was changed and I faced with issue after upgrade. The main reason is: I have enum like: {code:title=Pets.java|borderStyle=solid} // Some comments here public enum Pets { DOG_PET("Dog"), CAT_PET("Cat") private String displayValue; private Pets(String displayValue) { this.displayValue = displayValue; } @Override public String toString() { return displayValue; } } {code} As you see {code:borderStyle=solid}toString(){code} method overridden therefore {code:borderStyle=solid}DOG_PET.toString() != DOG_PET.name(){code} When 'select options' (combo box with enum) renders it uses {code:borderStyle=solid}typeCoercer.coerce(DOG_PET, enumType){code} to get value attribute for tag (before it was just {code:borderStyle=solid}DOG_PET.name() == "DOG_PET"{code}). Eventually we just get {code:borderStyle=solid}DOG_PET.toString() == "Dog"{code} as a result value. Then on submit {code:borderStyle=solid}StringToEnumCoercion{code} try to 'restore' selected option value to enum instance: - collect all enum values to map where key is: {code:borderStyle=solid}DOG_PET.name(){code} and value {code:borderStyle=solid}DOG_PET{code} - extract value from map (using option value as key == "Dog") Of course it has null result since "Dog" != "DOG_PET". In other word will not works if my enum has overridden {code:borderStyle=solid}toString(){code} method (it require custom encoder to work). I think it is need to use single mechanist to bind enum to string and vice versa in both cases: {code:borderStyle=solid}typeCoercer.coerce(value, String.class){code} or {code:borderStyle=solid}value.name(){code} > Inconsistent behavior of EnumValueEncoder > -- > > Key: TAP5-2496 > URL: https://issues.apache.org/jira/browse/TAP5-2496 > Project: Tapestry 5 > Issue Type: Bug >Affects Versions: 5.4 >Reporter: Jochen Kemnade >Assignee: Jochen Kemnade > Fix For: 5.4 > > > EnumValueEncoder uses {{java.lang.Enum.name()}} in {{toClient(E)}} but uses > {{typeCoercer.coerce(clientValue, enumType)}} in {{toValue(String > clientValue)}}. > I have a custom coercer in my project and this causes the value encoder to be > unable to decode the client-side value back to a server-side value. > I think we should remove {{EnumValueEncoderFactory}} altogether because > {{TypeCoercedValueEncoderFactory}} should do its job just fine. -- This message was sent by Atlassian JIRA (v6.3.4#6332)