-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADT: Bug fix: serialization issue with strings which starts with a nu…
…meric value. (#21623)
- Loading branch information
Showing
25 changed files
with
1,425 additions
and
789 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...igitaltwins-core/src/test/java/com/azure/digitaltwins/core/StringSerializerUnitTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.digitaltwins.core; | ||
|
||
import com.azure.digitaltwins.core.implementation.serializer.DigitalTwinsStringSerializer; | ||
import com.fasterxml.jackson.core.JsonFactory; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
|
||
public class StringSerializerUnitTests { | ||
|
||
private static DigitalTwinsStringSerializer serializer = new DigitalTwinsStringSerializer(String.class, new ObjectMapper()); | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = { | ||
"1234 | \"1234\"", | ||
"false | \"false\"", | ||
"true | \"true\"", | ||
"1234 room | \"1234 room\"", | ||
"{ \"a\" : 2 } | { \"a\" : 2 }", | ||
"{ \"a\" : false } | { \"a\" : false }", | ||
"{ \"a\" : \"false\" } | { \"a\" : \"false\" }", | ||
"{ \"a\" : \"some text\" } | { \"a\" : \"some text\" }", | ||
"[ 3, 2 ] | [ 3, 2 ]" | ||
}, delimiter = '|') | ||
public void serializeStringTokens(String input, String expected) throws IOException { | ||
String result = serializeTheToken(input); | ||
Assertions.assertEquals(expected, result); | ||
} | ||
|
||
private String serializeTheToken(String token) throws IOException { | ||
StringWriter writer = new StringWriter(); | ||
JsonGenerator generator = new JsonFactory().createGenerator(writer); | ||
|
||
serializer.serialize(token, generator, null); | ||
generator.flush(); | ||
generator.close(); | ||
|
||
return writer.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.