Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Issues
  • #1197
Closed
Open
Issue created Feb 25, 2020 by Administrator@rootContributor

Enum value not serialized as number

Created by: loewekordel

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.

Assignee
Assign to
Time tracking