question

Sara-8613 avatar image
0 Votes"
Sara-8613 asked ryanchill edited

LocationImpl representation as JSON

Hello,
I am using Azure SDK 1.40.0 and I am trying to create an API to return JSON response for LocationImpl class residing in com.microsoft.azure.management.resources.implementation package. Now, I was using an older SDK version before(1.33.0.1) and to return valid JSON, I was defining my representation like this. Looks like it is different now with SDK update and I am getting a NullPointerException java.lang.NullPointerException: null
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1838)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at java.lang.Double.valueOf(Double.java:502)

Old SDK;

 public class AzureRegionRepresentation { 
     @XmlElement 
     private String id; 
     
     @XmlElement 
     private String displayName; 
     
     @XmlElement 
     private String regionName; 
     
     @XmlElement 
     private Double latitude; 
     
     @XmlElement 
     private Double longitude; 
     
     public AzureRegionRepresentation() { 
     } 
     
         
     public AzureRegionRepresentation(Location azureLocation) { 
         id = azureLocation.inner().id(); 
             
         displayName = azureLocation.displayName(); 
            
         regionName = azureLocation.name(); 
         latitude = Double.valueOf(azureLocation.latitude()); 
         longitude = Double.valueOf(azureLocation.longitude()); 
     } 

New version of SDK:

 public class AzureRegionRepresentation { 
     @XmlElement 
     private String id; 
     
     @XmlElement 
     private String displayName; 
     
     @XmlElement 
     private String regionName; 
     
     @XmlElement 
     private Double latitude; 
     
     @XmlElement 
     private Double longitude; 
     
     public AzureRegionRepresentation() { 
     } 
     
        
     public AzureRegionRepresentation(Location azureLocation) { 
         id = azureLocation.inner().id(); 
            
         displayName = azureLocation.displayName(); 
         regionName = azureLocation.name(); 
         latitude = Double.valueOf(azureLocation.inner().metadata.latitude()); 
         longitude = Double.valueOf(azureLocation.inner().metadata.longitude()); 
     } 

Please tell me what I am doing wrong?

azure-webapps-development
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Sara-8613 just to verify, you are using Location class and getting null pointer exception? Looking at your class constructor, you've changed to use azureLocation.inner() instead of azureLocation.latitude. When you inspect the azureLocation what do you see?

0 Votes 0 ·

Yes,I am using Location class and yes, I am using azureLocation.inner().
The format inside Location class is different in updated SDK, as can be seen:

 @Override
     public String latitude() {
         return this.inner().metadata() == null ? null : this.inner().metadata().latitude();
     }
    
     @Override
     public String longitude() {
         return this.inner().metadata() == null ? null : this.inner().metadata().longitude();
     }

And I had to make changes to my AzureRegionRepresentation class to allow to define metadata. Makes sense?


0 Votes 0 ·

0 Answers