question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUERY] AzureJacksonAdapter fails to serialize map with key of resource ID

See original GitHub issue

Query/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:closed
  • Created 4 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
alzimmermsftcommented, Feb 25, 2020

Investigated with the help of @jianghaolu and we determined the reason that it is splitting the map key on . is due to VirtualMachineIdentity being final (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 triggers FlatteningSerializer to treat the Map property differently. It will early out on this line instead of hitting this code path.

A quick short term fix would be removing final from VirtualMachineIdentity.

0reactions
samvaitycommented, Oct 6, 2021

Fixed with ##22591 to allow flattening of static and final variables.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found