[QUERY] AzureJacksonAdapter fails to serialize map with key of resource ID
See original GitHub issueQuery/Question
We use AzureJacksonAdapter to serialize the VirtualMachineInner. It doesn’t work as expected when parsing the map inside the property of identity
.
Why is this not a Bug or a feature Request? Not sure if we missed adding some specific annotation in the object.
Code snippet to reproduce:
VirtualMachineInner inner = new VirtualMachineInner();
VirtualMachineIdentity identity = new VirtualMachineIdentity();
Map<String, VirtualMachineIdentityUserAssignedIdentities> map = new HashMap<>();
map.put("/subscriptions/0-0-0-0-0/resourcegroups/0/providers/Microsoft.ManagedIdentity/userAssignedIdentities/0",
new VirtualMachineIdentityUserAssignedIdentities());
identity.withType(ResourceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED);
identity.withUserAssignedIdentities(map);
inner.withIdentity(identity);
If we only serialize identity, we will get what we need
{
"type": "SystemAssigned, UserAssigned",
"userAssignedIdentities": {
"/subscriptions/0-0-0-0-0/resourcegroups/0/providers/Microsoft.ManagedIdentity/userAssignedIdentities/0": {}
}
}
But the actual what we get from inner is
"identity": {
"type": "SystemAssigned, UserAssigned",
"userAssignedIdentities": {
"/subscriptions/0-0-0-0-0/resourcegroups/0/providers/Microsoft": {
"ManagedIdentity/userAssignedIdentities/0": {}
}
}
},
Setup (please complete the following information if applicable):
- OS: Windows
- IDE : IntelliJ
- Version of the Library used
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Query Added
- Setup information Added
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Azure Core Nickel Semester #20995 - GitHub
[QUERY] AzureJacksonAdapter fails to serialize map with key of resource ID ... that run with restricted resource settings #20712) [Storage]
Read more >Why I'm not able to unwrap and serialize a Java map using the ...
@JsonUnwrapped doesn't work for maps, only for proper POJOs with getters and setters. For maps, You should use @JsonAnyGetter and @JsonAnySetter (available ...
Read more >"Element 'Id' does not match any field or property of class ...
Hello, I have a problem with the Project step in my Facet stage which maps Entity object into DTO: var dataFacet = AggregateFacet....
Read more >Map Serialization and Deserialization with Jackson - Baeldung
A quick and practical guide to serializing and deserializing Java Maps using Jackson.
Read more >(De)serialization - apischema
apischema aims to help with deserialization/serialization of API data, ... Define a schema with standard dataclasses @dataclass class Resource: id: UUID ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Investigated with the help of @jianghaolu and we determined the reason that it is splitting the map key on
.
is due toVirtualMachineIdentity
beingfinal
(https://github.com/Azure/azure-libraries-for-java/blob/vnext-compute-fix-tests/azure-mgmt-compute/src/main/java/com/azure/management/compute/VirtualMachineIdentity.java#L18), this triggersFlatteningSerializer
to treat theMap
property differently. It will early out on this line instead of hitting this code path.A quick short term fix would be removing
final
fromVirtualMachineIdentity
.Fixed with ##22591 to allow flattening of static and final variables.