SD-WAN

 View Only
  • 1.  getting Error Invalid Json Format

    Posted Aug 19, 2014 09:06 AM

    Hi

     

    We are trying to parse the response from of REST  command "/v2.0/net/nodes" and then we are getting an error INVALID JSON format.

     

    Below is the snippet of code.

     

    @GET
            @Produces(MediaType.APPLICATION_JSON)
            
            /* it returns the device information in a way the this
             * Device is connected with the particular switch.
             */
            private String getDeviceInfo(String hostMac) {
                 IpAddress ipAddress;
                      ipAddress=IpAddress.valueOf("127.0.0.1");
                      URI uri = restClient.uri(ipAddress, BASE_DESTINATION_PATH);
                    ResponseData response = restClient.get(restClient.login(), uri);
                    

                      String responseData;
                      try {
                      responseData = new String(response.data(), StringUtils.UTF8);
                      
                      } catch (UnsupportedEncodingException e) {
                      throw new RuntimeException(
                      "Unable to decode response from " + ipAddress, e);
                      }
                      log.warn("in getdeviceinfo() going to parse>>>>>>>.........");
                    
                      List<Switch> remote=jsonService.fromJsonList(responseData, Switch.class);
                      log.warn("in getdeviceinfo() with mac returned as"+ remote.get(0).getMac());
                      return null;

     

    }

     

    The higlighted line generates an error :-

    Caused by: com.hp.util.json.JsonCodecException: Invalid JSON format.
        at com.hp.util.json.AbstractJsonCodec.decodeList(AbstractJsonCodec.java:119)
        at com.hp.util.json.JSON.fromJsonList(JSON.java:82)
        at com.hp.sdn.rs.FlareJsonProvider.fromJsonList(FlareJsonProvider.java:87)
        at com.aricent.test.impl.LoadBalancerManager.getDeviceInfo(LoadBalancerManager.java:860)
        at com.aricent.test.impl.LoadBalancerManager.check(LoadBalancerManager.java:562)
        at com.aricent.test.impl.LoadBalancerManager.activate(LoadBalancerManager.java:254)
        ... 57 common frames omitted

    Are we missing anything, any help will be appreciated.

     

    Thanks

    Gurtej

     


               



  • 2.  RE: getting Error Invalid Json Format

    Posted Sep 02, 2014 02:22 PM

    Hello Gurtej,

     

    Please make sure that the BASE_DESTINATION_PATH( which is of type String for e.g.  "sdn/hm/v1.0/switches" ) , restClient (which is of type ServiceRest) and jsonService (which is of JsonService) is properly defined in the code.Also check that Switch.class is properly included.

     

    If you are still facing the problem , please share your code.

     

    Thanks,

    HP SDN Team