Skip to content

Commit 183b911

Browse files
committed
printer json BUGFIX union realtype value print
Fixes #1729
1 parent eb886d6 commit 183b911

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/printer_json.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,19 @@ static LY_ERR
333333
json_print_value(struct jsonpr_ctx *ctx, const struct lyd_value *val)
334334
{
335335
ly_bool dynamic;
336+
LY_DATA_TYPE basetype;
336337
const char *value = val->realtype->plugin->print(ctx->ctx, val, LY_VALUE_JSON, NULL, &dynamic, NULL);
337338

339+
basetype = val->realtype->basetype;
340+
341+
print_val:
338342
/* leafref is not supported */
339-
switch (val->realtype->basetype) {
343+
switch (basetype) {
344+
case LY_TYPE_UNION:
345+
/* use the resolved type */
346+
basetype = val->subvalue->value.realtype->basetype;
347+
goto print_val;
348+
340349
case LY_TYPE_BINARY:
341350
case LY_TYPE_STRING:
342351
case LY_TYPE_BITS:
@@ -346,7 +355,6 @@ json_print_value(struct jsonpr_ctx *ctx, const struct lyd_value *val)
346355
case LY_TYPE_UINT64:
347356
case LY_TYPE_DEC64:
348357
case LY_TYPE_IDENT:
349-
case LY_TYPE_UNION:
350358
json_print_string(ctx->out, value);
351359
break;
352360

0 commit comments

Comments
 (0)