0

I am using azure java sdk to collect assets from my azure account. I want to store the information in json format and later on i want to convert json back to original objects when needed. However when I serialize an object to json, its not writing all the properties. For example I am collecting Disk object as

PagedList<Disk> diskPagedList =azure.disks().list();
for(Disk disk: diskPagedList)
{
   String json = JsonSerializer.writeValueAsString(disk);
   //SaveToDatabase(json);
}

The returned json for each disk looks like

{"attachedToVirtualMachine":false,"inCreateMode":false,"hot":false}

It does not have any fields except three above. I tried with disk.inner() as well, it gives some more properties but those are also limited.

Is there a way to convert this complete object into json?

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67
Vineet Kumar
  • 176
  • 2
  • 11

1 Answers1

0

It does not have any fields except three above. I tried with disk.inner() as well, it gives some more properties but those are also limited.

In fact, the disk is an interface. As you mentioned, you could tried to use disk.inner to get the disk properties.

If it is also limited. I recommand you create a custom class to add other properties you wanted

public class DiskData {
    public DiskInner DiskInner;
    public String Otherproperty;// you want to store
    public String Anotherproperty;// you want to store        
    ...
}

The following is the demo code.

DiskData diskData = new DiskData();
for (Disk disk:diskPagedList)
{   
    diskData.DiskInner = disk.inner();
    diskData.Otherproperty= disk.regionName();
        ...
    String json = objectMapper.writeValueAsString(diskData);
}
Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47