forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix flattening serializer for maps (Azure#232)
* Fix flattening serializer for maps * Add test
- Loading branch information
1 parent
34666d3
commit cc553df
Showing
2 changed files
with
140 additions
and
56 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
45 changes: 45 additions & 0 deletions
45
client-runtime/src/test/java/com/microsoft/rest/FlatteningSerializerTests.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,45 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.rest; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.microsoft.rest.serializer.JacksonAdapter; | ||
import com.microsoft.rest.serializer.JsonFlatten; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class FlatteningSerializerTests { | ||
@Test | ||
public void canFlatten() throws Exception { | ||
Foo foo = new Foo(); | ||
foo.bar = "hello.world"; | ||
foo.baz = new ArrayList<>(); | ||
foo.baz.add("hello"); | ||
foo.baz.add("hello.world"); | ||
foo.qux = new HashMap<>(); | ||
foo.qux.put("hello", "world"); | ||
foo.qux.put("a.b", "c.d"); | ||
|
||
String serialized = new JacksonAdapter().serialize(foo); | ||
Assert.assertEquals("{\"properties\":{\"bar\":\"hello.world\",\"props\":{\"baz\":[\"hello\",\"hello.world\"],\"q\":{\"qux\":{\"a.b\":\"c.d\",\"hello\":\"world\"}}}}}", serialized); | ||
} | ||
|
||
@JsonFlatten | ||
private class Foo { | ||
@JsonProperty(value = "properties.bar") | ||
private String bar; | ||
@JsonProperty(value = "properties.props.baz") | ||
private List<String> baz; | ||
@JsonProperty(value = "properties.props.q.qux") | ||
private Map<String, String> qux; | ||
} | ||
} |