forcedotcom / EMP-Connector

A simplified cometd connector for Enterprise Messaging Platform
BSD 3-Clause "New" or "Revised" License
185 stars 243 forks source link

Missing full data back? #29

Closed shadowdogg closed 6 years ago

shadowdogg commented 6 years ago

On workbench it provides the following json:

{
  "channel": "/topic/Contact", 
  "clientId": "something", 
  "data": {
    "event": {
      "type": "updated", 
      "createdDate": "2018-01-31T15:08:09.000+0000"
    }, 
    "sobject": {
      "Fraud__c": null, 
      "Print_Subs_Amended__c": null, 
      "LastModifiedDate": "2018-01-31T15:07:57.000+0000" 
    }
  }
} 

However on this it provides:

{
    event = {
        createdDate = 2018 - 02 - 06 T12: 35: 13.560 Z,
        replayId = 171,
        type = updated
    }, sobject = {
        Webhelp_Account__c = false,
        LastModifiedDate = 2018 - 02 - 06 T12: 35: 13.000 Z
    }
}

How can it produce Json with all the existing data properly?

pbn-sfdc commented 6 years ago

@shadowdogg You could use ObjectMapper class to turn the event received into JSON string. For example,

        com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        Consumer<Map<String, Object>> consumer = event -> {
            StringWriter sw = new StringWriter();
            try {
                mapper.writeValue(sw, event);
                System.out.println(String.format("Received:\n%s", sw.toString()));
            } catch (IOException e) {
                e.printStackTrace();
            }
        };

will print

{
  "schema" : "ijXO8wCMNFGxuSCA9i_-zw",
  "payload" : {
    "CreatedById" : "005xx000001T01EAAS",
    "CreatedDate" : "2018-02-12T19:31:12Z",
    "status__c" : "This is desc 10",
    "status2__c" : "No value"
  },
  "event" : {
    "replayId" : 58263
  }
}