Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum value not serialized as number #1197

Closed
loewekordel opened this issue Feb 25, 2020 · 4 comments
Closed

Enum value not serialized as number #1197

loewekordel opened this issue Feb 25, 2020 · 4 comments
Labels
bug v6 ArduinoJson 6

Comments

@loewekordel
Copy link

platform: esp8266
ide: vscode + pio
ArduinoJson version: 6.14.1
Espressif 8266 version: 2.3.2
Arduino core version: 2.6.3

For error logging purposes, I created an enum and tried to serialize it, but the the enum number is not serialized. Instead true or false are written to the serialized buffer?

enum:

typedef enum errorMap_e {
  ERRC_OK  =   0,    // No Error
  ERRC_1   =   1,    // ERROR 1
  ERRC_2   =   2,    // ERROR 2
  ERRC_3   =   3,    // ERROR 3
  ERRC_4   =   4,    // ERROR 4
  ERRC_5   =   5,    // ERROR 5
  ERRC_6   =   6,    // ERROR 6
  ERRC_7   =   7,    // ERROR 7
  ERRC_8   =   8,    // ERROR 8
  ERRC_9   =   9,    // ERROR 9
  ERRC_10  =  10,    // ERROR 10
  ERRC_100 = 100     // ERROR 100
} errorMap_t;

ArduinoJson definitions:

StaticJsonDocument<150> jsonBuffer;
DeserializationError err;
char sendbuffer[256];

Serialization:

Serial.print("time: ");
Serial.print(errList[i].time);
Serial.print("  err: ");
Serial.println(errList[i].err);

// create json
jsonBuffer["cmd"] = "log";
jsonBuffer["time"] = errList[i].time;
jsonBuffer["err"] = errList[i].err;

// Send data only, if clients are connected
if (webSocket.connectedClients()) {
  size_t len = serializeJson(jsonBuffer, sendbuffer);
  if (len == 0) {
    Serial.println("Failed to serialize json");
  }
  DEBUGMSG(sendbuffer);

  // send data
  Serial.printf("Client updated %d - log\n", num);
  webSocket.sendTXT(num, sendbuffer, len);
}

Serial output (sendBuffer): {"cmd":"log","time":1582671207,"err":true}
I hope the explanation is good enough.

I appreciate your effort and would be very thankful for a hint.

@bblanchon
Copy link
Owner

Hi @loewekordel,

Thank you very much for reporting this issue.
This is clearly a bug.
Until I find a way to fix it, please cast the value to int:

jsonBuffer["err"] = (int)errList[i].err;

Best regards,
Benoit

@bblanchon bblanchon added the bug label Feb 26, 2020
bblanchon added a commit that referenced this issue Feb 26, 2020
bblanchon added a commit that referenced this issue Feb 26, 2020
@loewekordel
Copy link
Author

Hi @bblanchon,

I appreciate the quick analysis and fix!
Is there a plan, when the next version, including the fix, will be released?

Thank you very much!

Best regards,
Georg

@bblanchon
Copy link
Owner

The fix will be included in 6.15 in one or two weeks.

@bblanchon
Copy link
Owner

This fix was included in ArduinoJson 6.15.0.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
stawiski pushed a commit to stawiski/ArduinoJson that referenced this issue Jul 28, 2020
@bblanchon bblanchon added the v6 ArduinoJson 6 label Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug v6 ArduinoJson 6
Projects
None yet
Development

No branches or pull requests

2 participants