From a2ce3eecf3ee163d13bc0437e01e061ee0e22280 Mon Sep 17 00:00:00 2001 From: Will Godbe Date: Thu, 31 Dec 2020 13:02:56 -0800 Subject: [PATCH 01/14] Add docs for MessagePack --- aspnetcore/signalr/client-features.md | 2 +- aspnetcore/signalr/java-client.md | 1 - aspnetcore/signalr/java-client/sample/pom.xml | 7 ++ aspnetcore/signalr/messagepackhubprotocol.md | 84 +++++++++++++++++++ 4 files changed, 92 insertions(+), 2 deletions(-) diff --git a/aspnetcore/signalr/client-features.md b/aspnetcore/signalr/client-features.md index c32ffc546c2e..25607b95cf71 100644 --- a/aspnetcore/signalr/client-features.md +++ b/aspnetcore/signalr/client-features.md @@ -40,7 +40,7 @@ The table below shows the features and support for the clients that offer real-t | Server-Sent Events Transport |2.1.0|1.0.0|1.0.0|❌| | Long Polling Transport |2.1.0|1.0.0|1.0.0|3.0.0| | JSON Hub Protocol |2.1.0|1.0.0|1.0.0|1.0.0| -| MessagePack Hub Protocol |2.1.0|1.0.0|1.0.0|❌| +| MessagePack Hub Protocol |2.1.0|1.0.0|1.0.0|5.0.0| Support for enabling additional client features is tracked in [our issue tracker](https://github.com/dotnet/AspNetCore/issues). diff --git a/aspnetcore/signalr/java-client.md b/aspnetcore/signalr/java-client.md index 3268378307d0..951334a5fc46 100644 --- a/aspnetcore/signalr/java-client.md +++ b/aspnetcore/signalr/java-client.md @@ -95,7 +95,6 @@ HubConnection hubConnection = HubConnectionBuilder.create("YOUR HUB URL HERE") ::: moniker range=">= aspnetcore-3.0" -* Only the JSON protocol is supported. * Transport fallback and the Server Sent Events transport aren't supported. ::: moniker-end diff --git a/aspnetcore/signalr/java-client/sample/pom.xml b/aspnetcore/signalr/java-client/sample/pom.xml index 7994917233ea..325d87dbf6ad 100644 --- a/aspnetcore/signalr/java-client/sample/pom.xml +++ b/aspnetcore/signalr/java-client/sample/pom.xml @@ -28,6 +28,13 @@ 1.0.0 + + + com.microsoft.signalr.messagepack + signalr + 5.0.0 + + \ No newline at end of file diff --git a/aspnetcore/signalr/messagepackhubprotocol.md b/aspnetcore/signalr/messagepackhubprotocol.md index d721fcca2e40..fbd602fd766b 100644 --- a/aspnetcore/signalr/messagepackhubprotocol.md +++ b/aspnetcore/signalr/messagepackhubprotocol.md @@ -104,6 +104,26 @@ const connection = new signalR.HubConnectionBuilder() > [!NOTE] > At this time, there are no configuration options for the MessagePack protocol on the JavaScript client. +### Java client + +To enable MessagePack in the Java, first install the `com.microsoft.signalr.messagepack` package. If using Gradle, add the following line to the `dependencies` section of your *build.gradle* file: + +```gradle +implementation 'com.microsoft.signalr.messagepack:signalr-messagepack:5.0.0' +``` + +If using Maven, add the following lines inside the `` element of your *pom.xml* file: + +[!code-xml[pom.xml dependency element messagePack](java-client/sample/pom.xml?name=snippet_dependencyElement_messagePack)] + +Then call `withHubProtocol(new MessagePackHubProtocol())` on `HubConnectionBuilder`. + +```java +HubConnection messagePackConnection = HubConnectionBuilder.create("YOUR HUB URL HERE") + .withHubProtocol(new MessagePackHubProtocol()) + .build(); +``` + ## MessagePack quirks There are a few issues to be aware of when using the MessagePack Hub Protocol. @@ -172,6 +192,30 @@ InvalidDataException: Error binding arguments. Make sure that the types of the p For more information on this limitation, see GitHub issue [aspnet/SignalR#2937](https://github.com/aspnet/SignalR/issues/2937). +### Passing Class information in Java + +When calling the `on()`, `invoke()`, or `stream()` methods of `HubConnection` in the Java client, MessagePack users should pass a `Type` object rather than a `Class() { }).getType(); +Type barType = new TypeReference() { }).getType(); +``` + +Furthermore, when calling one of these methods with one or more object types, you should use the generics syntax when invoking the method. For example, if registering an `on` handler for a method named `func`, which takes as arguments a `Foo` object and a `Bar` object, you could use the following code to set an action to print the two objects: + +```java +hubConnection.on("func", (param1, param2) ->{ + System.out.println(param1); + System.out.println(param2); +}, fooType, barType); +``` + +The exception to this rule is primitives such as `int`, for which you should use the built-in `int.class`. + +### Chars and Strings in Java + +In the java client, `char` objects will be serialized as one-character `String`s. This is in contrast with the C# and JavaScript client, which serialize them as `short`s. The MessagePack spec itself does not define behavior for `char`s, so it is up to the library author to determine how to serialize them. The difference in behavior between our clients is a result of the libraries we used for our implementations. + ## Related resources * [Get Started](xref:tutorials/signalr) @@ -284,6 +328,26 @@ const connection = new signalR.HubConnectionBuilder() > [!NOTE] > At this time, there are no configuration options for the MessagePack protocol on the JavaScript client. +### Java client + +To enable MessagePack in the Java, first install the `com.microsoft.signalr.messagepack` package. If using Gradle, add the following line to the `dependencies` section of your *build.gradle* file: + +```gradle +implementation 'com.microsoft.signalr.messagepack:signalr-messagepack:5.0.0' +``` + +If using Maven, add the following lines inside the `` element of your *pom.xml* file: + +[!code-xml[pom.xml dependency element messagePack](java-client/sample/pom.xml?name=snippet_dependencyElement_messagePack)] + +Then call `withHubProtocol(new MessagePackHubProtocol())` on `HubConnectionBuilder`. + +```java +HubConnection messagePackConnection = HubConnectionBuilder.create("YOUR HUB URL HERE") + .withHubProtocol(new MessagePackHubProtocol()) + .build(); +``` + ## MessagePack quirks There are a few issues to be aware of when using the MessagePack Hub Protocol. @@ -464,6 +528,26 @@ const connection = new signalR.HubConnectionBuilder() > [!NOTE] > At this time, there are no configuration options for the MessagePack protocol on the JavaScript client. +### Java client + +To enable MessagePack in the Java, first install the `com.microsoft.signalr.messagepack` package. If using Gradle, add the following line to the `dependencies` section of your *build.gradle* file: + +```gradle +implementation 'com.microsoft.signalr.messagepack:signalr-messagepack:5.0.0' +``` + +If using Maven, add the following lines inside the `` element of your *pom.xml* file: + +[!code-xml[pom.xml dependency element messagePack](java-client/sample/pom.xml?name=snippet_dependencyElement_messagePack)] + +Then call `withHubProtocol(new MessagePackHubProtocol())` on `HubConnectionBuilder`. + +```java +HubConnection messagePackConnection = HubConnectionBuilder.create("YOUR HUB URL HERE") + .withHubProtocol(new MessagePackHubProtocol()) + .build(); +``` + ## MessagePack quirks There are a few issues to be aware of when using the MessagePack Hub Protocol. From 20f79f2f9dcab6cc217a965b0f883358033d85a6 Mon Sep 17 00:00:00 2001 From: Will Godbe Date: Thu, 31 Dec 2020 13:03:55 -0800 Subject: [PATCH 02/14] Triple up --- aspnetcore/signalr/messagepackhubprotocol.md | 48 ++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/aspnetcore/signalr/messagepackhubprotocol.md b/aspnetcore/signalr/messagepackhubprotocol.md index fbd602fd766b..0a3d2c3ed659 100644 --- a/aspnetcore/signalr/messagepackhubprotocol.md +++ b/aspnetcore/signalr/messagepackhubprotocol.md @@ -416,6 +416,30 @@ InvalidDataException: Error binding arguments. Make sure that the types of the p For more information on this limitation, see GitHub issue [aspnet/SignalR#2937](https://github.com/aspnet/SignalR/issues/2937). +### Passing Class information in Java + +When calling the `on()`, `invoke()`, or `stream()` methods of `HubConnection` in the Java client, MessagePack users should pass a `Type` object rather than a `Class() { }).getType(); +Type barType = new TypeReference() { }).getType(); +``` + +Furthermore, when calling one of these methods with one or more object types, you should use the generics syntax when invoking the method. For example, if registering an `on` handler for a method named `func`, which takes as arguments a `Foo` object and a `Bar` object, you could use the following code to set an action to print the two objects: + +```java +hubConnection.on("func", (param1, param2) ->{ + System.out.println(param1); + System.out.println(param2); +}, fooType, barType); +``` + +The exception to this rule is primitives such as `int`, for which you should use the built-in `int.class`. + +### Chars and Strings in Java + +In the java client, `char` objects will be serialized as one-character `String`s. This is in contrast with the C# and JavaScript client, which serialize them as `short`s. The MessagePack spec itself does not define behavior for `char`s, so it is up to the library author to determine how to serialize them. The difference in behavior between our clients is a result of the libraries we used for our implementations. + ## Related resources * [Get Started](xref:tutorials/signalr) @@ -616,6 +640,30 @@ InvalidDataException: Error binding arguments. Make sure that the types of the p For more information on this limitation, see GitHub issue [aspnet/SignalR#2937](https://github.com/aspnet/SignalR/issues/2937). +### Passing Class information in Java + +When calling the `on()`, `invoke()`, or `stream()` methods of `HubConnection` in the Java client, MessagePack users should pass a `Type` object rather than a `Class() { }).getType(); +Type barType = new TypeReference() { }).getType(); +``` + +Furthermore, when calling one of these methods with one or more object types, you should use the generics syntax when invoking the method. For example, if registering an `on` handler for a method named `func`, which takes as arguments a `Foo` object and a `Bar` object, you could use the following code to set an action to print the two objects: + +```java +hubConnection.on("func", (param1, param2) ->{ + System.out.println(param1); + System.out.println(param2); +}, fooType, barType); +``` + +The exception to this rule is primitives such as `int`, for which you should use the built-in `int.class`. + +### Chars and Strings in Java + +In the java client, `char` objects will be serialized as one-character `String`s. This is in contrast with the C# and JavaScript client, which serialize them as `short`s. The MessagePack spec itself does not define behavior for `char`s, so it is up to the library author to determine how to serialize them. The difference in behavior between our clients is a result of the libraries we used for our implementations. + ## Related resources * [Get Started](xref:tutorials/signalr) From a4d121d067d1e4ff45959b25b92bbe356ec1a757 Mon Sep 17 00:00:00 2001 From: William Godbe Date: Thu, 31 Dec 2020 13:24:33 -0800 Subject: [PATCH 03/14] Update messagepackhubprotocol.md --- aspnetcore/signalr/messagepackhubprotocol.md | 88 -------------------- 1 file changed, 88 deletions(-) diff --git a/aspnetcore/signalr/messagepackhubprotocol.md b/aspnetcore/signalr/messagepackhubprotocol.md index 0a3d2c3ed659..ead0ecdd95f9 100644 --- a/aspnetcore/signalr/messagepackhubprotocol.md +++ b/aspnetcore/signalr/messagepackhubprotocol.md @@ -328,26 +328,6 @@ const connection = new signalR.HubConnectionBuilder() > [!NOTE] > At this time, there are no configuration options for the MessagePack protocol on the JavaScript client. -### Java client - -To enable MessagePack in the Java, first install the `com.microsoft.signalr.messagepack` package. If using Gradle, add the following line to the `dependencies` section of your *build.gradle* file: - -```gradle -implementation 'com.microsoft.signalr.messagepack:signalr-messagepack:5.0.0' -``` - -If using Maven, add the following lines inside the `` element of your *pom.xml* file: - -[!code-xml[pom.xml dependency element messagePack](java-client/sample/pom.xml?name=snippet_dependencyElement_messagePack)] - -Then call `withHubProtocol(new MessagePackHubProtocol())` on `HubConnectionBuilder`. - -```java -HubConnection messagePackConnection = HubConnectionBuilder.create("YOUR HUB URL HERE") - .withHubProtocol(new MessagePackHubProtocol()) - .build(); -``` - ## MessagePack quirks There are a few issues to be aware of when using the MessagePack Hub Protocol. @@ -416,30 +396,6 @@ InvalidDataException: Error binding arguments. Make sure that the types of the p For more information on this limitation, see GitHub issue [aspnet/SignalR#2937](https://github.com/aspnet/SignalR/issues/2937). -### Passing Class information in Java - -When calling the `on()`, `invoke()`, or `stream()` methods of `HubConnection` in the Java client, MessagePack users should pass a `Type` object rather than a `Class() { }).getType(); -Type barType = new TypeReference() { }).getType(); -``` - -Furthermore, when calling one of these methods with one or more object types, you should use the generics syntax when invoking the method. For example, if registering an `on` handler for a method named `func`, which takes as arguments a `Foo` object and a `Bar` object, you could use the following code to set an action to print the two objects: - -```java -hubConnection.on("func", (param1, param2) ->{ - System.out.println(param1); - System.out.println(param2); -}, fooType, barType); -``` - -The exception to this rule is primitives such as `int`, for which you should use the built-in `int.class`. - -### Chars and Strings in Java - -In the java client, `char` objects will be serialized as one-character `String`s. This is in contrast with the C# and JavaScript client, which serialize them as `short`s. The MessagePack spec itself does not define behavior for `char`s, so it is up to the library author to determine how to serialize them. The difference in behavior between our clients is a result of the libraries we used for our implementations. - ## Related resources * [Get Started](xref:tutorials/signalr) @@ -552,26 +508,6 @@ const connection = new signalR.HubConnectionBuilder() > [!NOTE] > At this time, there are no configuration options for the MessagePack protocol on the JavaScript client. -### Java client - -To enable MessagePack in the Java, first install the `com.microsoft.signalr.messagepack` package. If using Gradle, add the following line to the `dependencies` section of your *build.gradle* file: - -```gradle -implementation 'com.microsoft.signalr.messagepack:signalr-messagepack:5.0.0' -``` - -If using Maven, add the following lines inside the `` element of your *pom.xml* file: - -[!code-xml[pom.xml dependency element messagePack](java-client/sample/pom.xml?name=snippet_dependencyElement_messagePack)] - -Then call `withHubProtocol(new MessagePackHubProtocol())` on `HubConnectionBuilder`. - -```java -HubConnection messagePackConnection = HubConnectionBuilder.create("YOUR HUB URL HERE") - .withHubProtocol(new MessagePackHubProtocol()) - .build(); -``` - ## MessagePack quirks There are a few issues to be aware of when using the MessagePack Hub Protocol. @@ -640,30 +576,6 @@ InvalidDataException: Error binding arguments. Make sure that the types of the p For more information on this limitation, see GitHub issue [aspnet/SignalR#2937](https://github.com/aspnet/SignalR/issues/2937). -### Passing Class information in Java - -When calling the `on()`, `invoke()`, or `stream()` methods of `HubConnection` in the Java client, MessagePack users should pass a `Type` object rather than a `Class() { }).getType(); -Type barType = new TypeReference() { }).getType(); -``` - -Furthermore, when calling one of these methods with one or more object types, you should use the generics syntax when invoking the method. For example, if registering an `on` handler for a method named `func`, which takes as arguments a `Foo` object and a `Bar` object, you could use the following code to set an action to print the two objects: - -```java -hubConnection.on("func", (param1, param2) ->{ - System.out.println(param1); - System.out.println(param2); -}, fooType, barType); -``` - -The exception to this rule is primitives such as `int`, for which you should use the built-in `int.class`. - -### Chars and Strings in Java - -In the java client, `char` objects will be serialized as one-character `String`s. This is in contrast with the C# and JavaScript client, which serialize them as `short`s. The MessagePack spec itself does not define behavior for `char`s, so it is up to the library author to determine how to serialize them. The difference in behavior between our clients is a result of the libraries we used for our implementations. - ## Related resources * [Get Started](xref:tutorials/signalr) From 743f99797415e2b958a5c194e6caec7a860abb44 Mon Sep 17 00:00:00 2001 From: William Godbe Date: Mon, 4 Jan 2021 10:11:27 -0800 Subject: [PATCH 04/14] Update aspnetcore/signalr/messagepackhubprotocol.md Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> --- aspnetcore/signalr/messagepackhubprotocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/signalr/messagepackhubprotocol.md b/aspnetcore/signalr/messagepackhubprotocol.md index ead0ecdd95f9..323c5214e8a5 100644 --- a/aspnetcore/signalr/messagepackhubprotocol.md +++ b/aspnetcore/signalr/messagepackhubprotocol.md @@ -106,7 +106,7 @@ const connection = new signalR.HubConnectionBuilder() ### Java client -To enable MessagePack in the Java, first install the `com.microsoft.signalr.messagepack` package. If using Gradle, add the following line to the `dependencies` section of your *build.gradle* file: +To enable MessagePack with Java, install the `com.microsoft.signalr.messagepack` package. When using Gradle, add the following line to the `dependencies` section of the *build.gradle* file: ```gradle implementation 'com.microsoft.signalr.messagepack:signalr-messagepack:5.0.0' From bf7f85dbdc21487e129fc9caa28bf88f6bc13d8f Mon Sep 17 00:00:00 2001 From: William Godbe Date: Mon, 4 Jan 2021 10:11:36 -0800 Subject: [PATCH 05/14] Update aspnetcore/signalr/messagepackhubprotocol.md Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> --- aspnetcore/signalr/messagepackhubprotocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/signalr/messagepackhubprotocol.md b/aspnetcore/signalr/messagepackhubprotocol.md index 323c5214e8a5..dc63b6f2025b 100644 --- a/aspnetcore/signalr/messagepackhubprotocol.md +++ b/aspnetcore/signalr/messagepackhubprotocol.md @@ -112,7 +112,7 @@ To enable MessagePack with Java, install the `com.microsoft.signalr.messagepack` implementation 'com.microsoft.signalr.messagepack:signalr-messagepack:5.0.0' ``` -If using Maven, add the following lines inside the `` element of your *pom.xml* file: +When using Maven, add the following lines inside the `` element of the *pom.xml* file: [!code-xml[pom.xml dependency element messagePack](java-client/sample/pom.xml?name=snippet_dependencyElement_messagePack)] From 0e80ae652f0aeb905bd0b8f1f419859dda0b571c Mon Sep 17 00:00:00 2001 From: William Godbe Date: Mon, 4 Jan 2021 10:11:56 -0800 Subject: [PATCH 06/14] Update aspnetcore/signalr/messagepackhubprotocol.md Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> --- aspnetcore/signalr/messagepackhubprotocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/signalr/messagepackhubprotocol.md b/aspnetcore/signalr/messagepackhubprotocol.md index dc63b6f2025b..9ba9ec97d5db 100644 --- a/aspnetcore/signalr/messagepackhubprotocol.md +++ b/aspnetcore/signalr/messagepackhubprotocol.md @@ -116,7 +116,7 @@ When using Maven, add the following lines inside the `` element of [!code-xml[pom.xml dependency element messagePack](java-client/sample/pom.xml?name=snippet_dependencyElement_messagePack)] -Then call `withHubProtocol(new MessagePackHubProtocol())` on `HubConnectionBuilder`. +Call `withHubProtocol(new MessagePackHubProtocol())` on `HubConnectionBuilder`. ```java HubConnection messagePackConnection = HubConnectionBuilder.create("YOUR HUB URL HERE") From 468da26ffed17b70514e06901ed357ccb3cf702a Mon Sep 17 00:00:00 2001 From: William Godbe Date: Mon, 4 Jan 2021 10:12:24 -0800 Subject: [PATCH 07/14] Update aspnetcore/signalr/messagepackhubprotocol.md Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> --- aspnetcore/signalr/messagepackhubprotocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/signalr/messagepackhubprotocol.md b/aspnetcore/signalr/messagepackhubprotocol.md index 9ba9ec97d5db..c8cf234389d6 100644 --- a/aspnetcore/signalr/messagepackhubprotocol.md +++ b/aspnetcore/signalr/messagepackhubprotocol.md @@ -194,7 +194,7 @@ For more information on this limitation, see GitHub issue [aspnet/SignalR#2937]( ### Passing Class information in Java -When calling the `on()`, `invoke()`, or `stream()` methods of `HubConnection` in the Java client, MessagePack users should pass a `Type` object rather than a `Class() { }).getType(); From f4396484459addd08b718b96f423bdf6663564c3 Mon Sep 17 00:00:00 2001 From: William Godbe Date: Mon, 4 Jan 2021 10:12:35 -0800 Subject: [PATCH 08/14] Update aspnetcore/signalr/messagepackhubprotocol.md Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> --- aspnetcore/signalr/messagepackhubprotocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/signalr/messagepackhubprotocol.md b/aspnetcore/signalr/messagepackhubprotocol.md index c8cf234389d6..96612e467dd0 100644 --- a/aspnetcore/signalr/messagepackhubprotocol.md +++ b/aspnetcore/signalr/messagepackhubprotocol.md @@ -210,7 +210,7 @@ hubConnection.on("func", (param1, param2) ->{ }, fooType, barType); ``` -The exception to this rule is primitives such as `int`, for which you should use the built-in `int.class`. +The exception to this rule is primitives such as `int`. When using `int`, use the built-in `int.class`. ### Chars and Strings in Java From 5530a9744f06c1fb879040e44506feea605b3722 Mon Sep 17 00:00:00 2001 From: Will Godbe Date: Mon, 4 Jan 2021 10:17:11 -0800 Subject: [PATCH 09/14] Feedback 1 --- aspnetcore/signalr/messagepackhubprotocol.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aspnetcore/signalr/messagepackhubprotocol.md b/aspnetcore/signalr/messagepackhubprotocol.md index 96612e467dd0..b21bc8eac430 100644 --- a/aspnetcore/signalr/messagepackhubprotocol.md +++ b/aspnetcore/signalr/messagepackhubprotocol.md @@ -194,14 +194,14 @@ For more information on this limitation, see GitHub issue [aspnet/SignalR#2937]( ### Passing Class information in Java -When calling the `on`, `invoke`, or `stream` methods of `HubConnection` in the Java client, MessagePack users should pass a `Type` object rather than a `Class` object to describe each `Object` passed to the method. A `Type` can be acquired using the provided `TypeReference` class. For example, using a custom classes named `Foo` and `Bar`, the following code gets each `Type`: ```java Type fooType = new TypeReference() { }).getType(); Type barType = new TypeReference() { }).getType(); ``` -Furthermore, when calling one of these methods with one or more object types, you should use the generics syntax when invoking the method. For example, if registering an `on` handler for a method named `func`, which takes as arguments a `Foo` object and a `Bar` object, you could use the following code to set an action to print the two objects: +When calling one of these methods with one or more object types, use the generics syntax when invoking the method. For example, when registering an `on` handler for a method named `func`, which takes as arguments a `Foo` object and a `Bar` object, use the following code to set an action to print the two objects: ```java hubConnection.on("func", (param1, param2) ->{ @@ -214,7 +214,7 @@ The exception to this rule is primitives such as `int`. When using `int`, use th ### Chars and Strings in Java -In the java client, `char` objects will be serialized as one-character `String`s. This is in contrast with the C# and JavaScript client, which serialize them as `short`s. The MessagePack spec itself does not define behavior for `char`s, so it is up to the library author to determine how to serialize them. The difference in behavior between our clients is a result of the libraries we used for our implementations. +In the java client, `char` objects will be serialized as one-character `String` objects. This is in contrast with the C# and JavaScript client, which serialize them as `short` objects. The MessagePack spec itself does not define behavior for `char` objects, so it is up to the library author to determine how to serialize them. The difference in behavior between our clients is a result of the libraries we used for our implementations. ## Related resources From 2dd68d67313691ece9913f6ab8ea6fc03c429f63 Mon Sep 17 00:00:00 2001 From: Will Godbe Date: Mon, 4 Jan 2021 10:26:45 -0800 Subject: [PATCH 10/14] More feedback --- aspnetcore/signalr/java-client.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/aspnetcore/signalr/java-client.md b/aspnetcore/signalr/java-client.md index 951334a5fc46..1b8acf7e70ea 100644 --- a/aspnetcore/signalr/java-client.md +++ b/aspnetcore/signalr/java-client.md @@ -93,12 +93,19 @@ HubConnection hubConnection = HubConnectionBuilder.create("YOUR HUB URL HERE") ## Known limitations -::: moniker range=">= aspnetcore-3.0" +::: moniker range=">= aspnetcore-5.0" * Transport fallback and the Server Sent Events transport aren't supported. ::: moniker-end +::: moniker range=">= aspnetcore-3.0" < aspnetcore-5.0" + +* Transport fallback and the Server Sent Events transport aren't supported. +* Only the JSON protocol is supported. + +::: moniker-end + ::: moniker range="< aspnetcore-3.0" * Only the JSON protocol is supported. From fd51aba3760da7845281f792159238d121ee3741 Mon Sep 17 00:00:00 2001 From: Will Godbe Date: Tue, 5 Jan 2021 12:45:19 -0800 Subject: [PATCH 11/14] Move TypeReference info to Java-client.md --- aspnetcore/signalr/java-client.md | 26 ++++++++++++++++++++ aspnetcore/signalr/messagepackhubprotocol.md | 20 --------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/aspnetcore/signalr/java-client.md b/aspnetcore/signalr/java-client.md index 1b8acf7e70ea..feb86b445142 100644 --- a/aspnetcore/signalr/java-client.md +++ b/aspnetcore/signalr/java-client.md @@ -91,6 +91,32 @@ HubConnection hubConnection = HubConnectionBuilder.create("YOUR HUB URL HERE") })).build(); ``` +::: moniker range=">= aspnetcore-5.0" + +### Passing Class information in Java + +When calling the `on`, `invoke`, or `stream` methods of `HubConnection` in the Java client, users should pass a `Type` object rather than a `Class` object to describe each `Object` passed to the method. A `Type` can be acquired using the provided `TypeReference` class. For example, using a custom classes named `Foo` and `Bar`, the following code gets each `Type`: + +```java +Type fooType = new TypeReference() { }).getType(); +Type barType = new TypeReference() { }).getType(); +``` + +When calling one of these methods with one or more object types, use the generics syntax when invoking the method. For example, when registering an `on` handler for a method named `func`, which takes as arguments a `Foo` object and a `Bar` object, use the following code to set an action to print the two objects: + +```java +hubConnection.on("func", (param1, param2) ->{ + System.out.println(param1); + System.out.println(param2); +}, fooType, barType); +``` + +The reason that this convention is necessary is, due to type erasure in Java, we can not retrieve complete information about complex types with the `Object.getClass` method. For example, calling `getClass` on an `ArrayList` would not return `Class>`, but rather `Class`, which does not give the deserializer enough information to correctly deserialize an incoming message. The same is true for custom objects. + +The exception to this rule is primitives such as `int`. When using `int`, use the built-in `int.class`. + +::: moniker-end + ## Known limitations ::: moniker range=">= aspnetcore-5.0" diff --git a/aspnetcore/signalr/messagepackhubprotocol.md b/aspnetcore/signalr/messagepackhubprotocol.md index b21bc8eac430..9c80d56e9bce 100644 --- a/aspnetcore/signalr/messagepackhubprotocol.md +++ b/aspnetcore/signalr/messagepackhubprotocol.md @@ -192,26 +192,6 @@ InvalidDataException: Error binding arguments. Make sure that the types of the p For more information on this limitation, see GitHub issue [aspnet/SignalR#2937](https://github.com/aspnet/SignalR/issues/2937). -### Passing Class information in Java - -When calling the `on`, `invoke`, or `stream` methods of `HubConnection` in the Java client, MessagePack users should pass a `Type` object rather than a `Class` object to describe each `Object` passed to the method. A `Type` can be acquired using the provided `TypeReference` class. For example, using a custom classes named `Foo` and `Bar`, the following code gets each `Type`: - -```java -Type fooType = new TypeReference() { }).getType(); -Type barType = new TypeReference() { }).getType(); -``` - -When calling one of these methods with one or more object types, use the generics syntax when invoking the method. For example, when registering an `on` handler for a method named `func`, which takes as arguments a `Foo` object and a `Bar` object, use the following code to set an action to print the two objects: - -```java -hubConnection.on("func", (param1, param2) ->{ - System.out.println(param1); - System.out.println(param2); -}, fooType, barType); -``` - -The exception to this rule is primitives such as `int`. When using `int`, use the built-in `int.class`. - ### Chars and Strings in Java In the java client, `char` objects will be serialized as one-character `String` objects. This is in contrast with the C# and JavaScript client, which serialize them as `short` objects. The MessagePack spec itself does not define behavior for `char` objects, so it is up to the library author to determine how to serialize them. The difference in behavior between our clients is a result of the libraries we used for our implementations. From 751e156a41b84b410b1c2c391fb55385bdeebba9 Mon Sep 17 00:00:00 2001 From: William Godbe Date: Tue, 5 Jan 2021 13:03:44 -0800 Subject: [PATCH 12/14] Update aspnetcore/signalr/java-client.md Co-authored-by: Stephen Halter --- aspnetcore/signalr/java-client.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/signalr/java-client.md b/aspnetcore/signalr/java-client.md index feb86b445142..5e5872f7b047 100644 --- a/aspnetcore/signalr/java-client.md +++ b/aspnetcore/signalr/java-client.md @@ -111,7 +111,7 @@ hubConnection.on("func", (param1, param2) ->{ }, fooType, barType); ``` -The reason that this convention is necessary is, due to type erasure in Java, we can not retrieve complete information about complex types with the `Object.getClass` method. For example, calling `getClass` on an `ArrayList` would not return `Class>`, but rather `Class`, which does not give the deserializer enough information to correctly deserialize an incoming message. The same is true for custom objects. +This convention is necessary because we can not retrieve complete information about complex types with the `Object.getClass` method due to type erasure in Java. For example, calling `getClass` on an `ArrayList` would not return `Class>`, but rather `Class`, which does not give the deserializer enough information to correctly deserialize an incoming message. The same is true for custom objects. The exception to this rule is primitives such as `int`. When using `int`, use the built-in `int.class`. From db837b633be4c79fe87a53a32bd5053242627c3a Mon Sep 17 00:00:00 2001 From: Will Godbe Date: Tue, 5 Jan 2021 13:13:38 -0800 Subject: [PATCH 13/14] Feedback --- aspnetcore/signalr/java-client.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/aspnetcore/signalr/java-client.md b/aspnetcore/signalr/java-client.md index 5e5872f7b047..0a01886b1630 100644 --- a/aspnetcore/signalr/java-client.md +++ b/aspnetcore/signalr/java-client.md @@ -95,26 +95,25 @@ HubConnection hubConnection = HubConnectionBuilder.create("YOUR HUB URL HERE") ### Passing Class information in Java -When calling the `on`, `invoke`, or `stream` methods of `HubConnection` in the Java client, users should pass a `Type` object rather than a `Class` object to describe each `Object` passed to the method. A `Type` can be acquired using the provided `TypeReference` class. For example, using a custom classes named `Foo` and `Bar`, the following code gets each `Type`: +When calling the `on`, `invoke`, or `stream` methods of `HubConnection` in the Java client, users should pass a `Type` object rather than a `Class` object to describe any generic `Object` passed to the method. A `Type` can be acquired using the provided `TypeReference` class. For example, using a custom generic class named `Foo`, the following code gets the `Type`: ```java -Type fooType = new TypeReference() { }).getType(); -Type barType = new TypeReference() { }).getType(); +Type fooType = new TypeReference>() { }).getType(); ``` -When calling one of these methods with one or more object types, use the generics syntax when invoking the method. For example, when registering an `on` handler for a method named `func`, which takes as arguments a `Foo` object and a `Bar` object, use the following code to set an action to print the two objects: +For non-generics, such as primitives or other non-parameterized types like `String`, you can simply use the built-in `.class`. + +When calling one of these methods with one or more object types, use the generics syntax when invoking the method. For example, when registering an `on` handler for a method named `func`, which takes as arguments a String and a `Foo` object, use the following code to set an action to print the arguments: ```java -hubConnection.on("func", (param1, param2) ->{ +hubConnection.>on("func", (param1, param2) ->{ System.out.println(param1); System.out.println(param2); -}, fooType, barType); +}, String.class, fooType); ``` This convention is necessary because we can not retrieve complete information about complex types with the `Object.getClass` method due to type erasure in Java. For example, calling `getClass` on an `ArrayList` would not return `Class>`, but rather `Class`, which does not give the deserializer enough information to correctly deserialize an incoming message. The same is true for custom objects. -The exception to this rule is primitives such as `int`. When using `int`, use the built-in `int.class`. - ::: moniker-end ## Known limitations From 8c1449aec9812de2c45fec2b404c013f974af297 Mon Sep 17 00:00:00 2001 From: William Godbe Date: Tue, 5 Jan 2021 13:51:28 -0800 Subject: [PATCH 14/14] Update aspnetcore/signalr/java-client.md Co-authored-by: Stephen Halter --- aspnetcore/signalr/java-client.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/signalr/java-client.md b/aspnetcore/signalr/java-client.md index 0a01886b1630..c2ae3cc09ce6 100644 --- a/aspnetcore/signalr/java-client.md +++ b/aspnetcore/signalr/java-client.md @@ -124,7 +124,7 @@ This convention is necessary because we can not retrieve complete information ab ::: moniker-end -::: moniker range=">= aspnetcore-3.0" < aspnetcore-5.0" +::: moniker range=">= aspnetcore-3.0 < aspnetcore-5.0" * Transport fallback and the Server Sent Events transport aren't supported. * Only the JSON protocol is supported.