Skip to content

Commit 655c247

Browse files
[Service Bus] ATOM API: Correlation Filter - int and double as values under properties (Azure#12349)
### Issue Azure#9850 (part 9) ### Description This PR is regarding the serialization/deserialization of int-double-number types in the applicationProps under correlation rule filter and the optimal way to support them in the SDK. <img src="https://user-images.githubusercontent.com/10452642/98731900-3eee6280-2353-11eb-8da1-81c0e8cb731d.png" height=150> #### Before this PR All numbers are treated as "int" #### With this PR For serialization, numbers are treated as "double". During deserialization, "int" and "double" are treated as numbers.(To allow interop) Reference Azure#9850 (comment)
1 parent b643478 commit 655c247

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

sdk/servicebus/service-bus/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 7.0.0 (Unreleased)
44

5+
- Numbers passed in `applicationProperties` of the correlation rule filter and `sqlParameters` under SQLRuleFilter will now be serialized as "double"(used to be "int") while sending the requests. The "double" and "int" values in the response will now be deserialized as "number"("double" wasn't supported before).
6+
[PR 12349](https://github.com/Azure/azure-sdk-for-js/pull/12349)
7+
58
## 7.0.0-preview.8 (2020-11-04)
69

710
### New features:

sdk/servicebus/service-bus/src/serializers/ruleResourceSerializer.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -252,24 +252,25 @@ export function isSqlRuleAction(action: any): action is SqlRuleAction {
252252
* @internal
253253
* @ignore
254254
*/
255-
const TypeMapForRequestSerialization: Record<string, string> = {
256-
int: "l28:int",
257-
string: "l28:string",
258-
long: "l28:long",
259-
date: "l28:dateTime",
260-
boolean: "l28:boolean"
261-
};
255+
enum TypeMapForRequestSerialization {
256+
double = "l28:double",
257+
string = "l28:string",
258+
long = "l28:long",
259+
date = "l28:dateTime",
260+
boolean = "l28:boolean"
261+
}
262262

263263
/**
264264
* @internal
265265
* @ignore
266266
*/
267-
const TypeMapForResponseDeserialization: Record<string, string> = {
268-
number: "int",
269-
string: "string",
270-
boolean: "boolean",
271-
date: "dateTime"
272-
};
267+
enum TypeMapForResponseDeserialization {
268+
int = "int",
269+
double = "double",
270+
string = "string",
271+
boolean = "boolean",
272+
date = "dateTime"
273+
}
273274

274275
/**
275276
* @internal
@@ -325,15 +326,20 @@ function getKeyValuePairsOrUndefined(
325326
}
326327
if (Array.isArray(rawProperties)) {
327328
for (const rawProperty of rawProperties) {
329+
const key = rawProperty.Key;
330+
const value = rawProperty.Value["_"];
328331
const encodedValueType = rawProperty.Value["$"]["i:type"].toString().substring(5);
329-
if (encodedValueType === TypeMapForResponseDeserialization.number) {
330-
properties[rawProperty.Key] = Number(rawProperty.Value["_"]);
332+
if (
333+
encodedValueType === TypeMapForResponseDeserialization.int ||
334+
encodedValueType === TypeMapForResponseDeserialization.double
335+
) {
336+
properties[key] = Number(value);
331337
} else if (encodedValueType === TypeMapForResponseDeserialization.string) {
332-
properties[rawProperty.Key] = rawProperty.Value["_"];
338+
properties[key] = value;
333339
} else if (encodedValueType === TypeMapForResponseDeserialization.boolean) {
334-
properties[rawProperty.Key] = rawProperty.Value["_"] === "true" ? true : false;
340+
properties[key] = value === "true" ? true : false;
335341
} else if (encodedValueType === TypeMapForResponseDeserialization.date) {
336-
properties[rawProperty.Key] = new Date(rawProperty.Value["_"]);
342+
properties[key] = new Date(value);
337343
} else {
338344
throw new TypeError(
339345
`Unable to parse the key-value pairs in the response - ${JSON.stringify(rawProperty)}`
@@ -380,7 +386,7 @@ export function buildInternalRawKeyValuePairs(
380386
for (let [key, value] of Object.entries(parameters)) {
381387
let type: string | number | boolean;
382388
if (typeof value === "number") {
383-
type = TypeMapForRequestSerialization.int;
389+
type = TypeMapForRequestSerialization.double;
384390
} else if (typeof value === "string") {
385391
type = TypeMapForRequestSerialization.string;
386392
} else if (typeof value === "boolean") {

sdk/servicebus/service-bus/test/atomManagement.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,9 @@ const createRuleTests: {
17681768
applicationProperties: {
17691769
randomState: "WA",
17701770
randomCountry: "US",
1771-
randomCount: 25,
1771+
randomInt: 25,
1772+
randomIntDisguisedAsDouble: 3.0,
1773+
randomDouble: 12.4,
17721774
randomBool: true,
17731775
randomDate: randomDate
17741776
}
@@ -1788,7 +1790,9 @@ const createRuleTests: {
17881790
applicationProperties: {
17891791
randomState: "WA",
17901792
randomCountry: "US",
1791-
randomCount: 25,
1793+
randomInt: 25,
1794+
randomIntDisguisedAsDouble: 3.0,
1795+
randomDouble: 12.4,
17921796
randomBool: true,
17931797
randomDate: randomDate
17941798
}

0 commit comments

Comments
 (0)