gnxi icon indicating copy to clipboard operation
gnxi copied to clipboard

JSON encoding not supported for leaf-nodes

Open vainyksi opened this issue 6 years ago • 1 comments

Hi,

1. I have problem to set leaf node with with json_val.

sending update request:

update {
  path {
    elem {
      name: "system"
    }
    elem {
      name: "config"
    }
    elem {
      name: "domain-name"
    }
  }
  val {
    json_val: "domain-name.com"
  }
}

returns error: INTERNAL: cannot convert leaf node to scalar type: non-scalar type &{JsonVal:[100 111 109 97 105 110 45 110 97 109 101 46 99 111 109]}

The specification tells that the value node should be encoded by oneof the scalar types or structural types ... .

Also in the 2.3.1 JSON and JSON_IETF there is example how string or uint32 leaf-node can be serialized.

So I think the server should be able to apply also scalar type

val {
  string_val: "domain-name.com"
}

but also JSON type

val {
  json_val: "domain-name.com"
}

2. Also the server does not return json_val for leaf-nodes. When the encoding is explicitly specified in get request:

path {
  elem {
    name: "system"
  }
  elem {
    name: "config"
  }
  elem {
    name: "domain-name"
  }
}
encoding: JSON_IETF

It returns val as string_val. I would expect json_val.

notification {
  timestamp: 1532431023993295089
  update {
    path {
      elem {
        name: "system"
      }
      elem {
        name: "config"
      }
      elem {
        name: "domain-name"
      }
    }
    val {
      string_val: "domain-name.com"
    }
  }
}

Same response returned even when encoding is not specified. The specification tells that If the client does not specify the encoding in an RPC message, it MUST send JSON encoded values (the default encoding). So I would expect to get at least json_val also when no encoding was specified.

Or did I understand it wrong? Please correct me if so.

vainyksi avatar Jul 24 '18 11:07 vainyksi

Just ran into this using json_ietf_val when updating a single leaf node (had to use string_val).

Perhaps this can be explained by https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-specification.md#223-node-values which does not explicitly list json or json_ietf_val as possible options but it does mention it must be a TypedValue which the proto definition does have in the oneof: https://github.com/openconfig/gnmi/blob/5473f2ef722ee45c3f26eee3f4a44a7d827e3575/proto/gnmi/gnmi.proto#L108

So it's not clear IMO.

xavier-contreras avatar Jul 24 '23 22:07 xavier-contreras