-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
ClientThis issue points to a problem in the data-plane of the library.This issue points to a problem in the data-plane of the library.Event Gridcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.Issues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as thatThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
Description
Describe the bug
Due to the current implementation of CloudEvent, the data attribute of the CloudEvent is represented as org.example.functions.SerializableContent instead of the desired class.
To Reproduce
Steps to reproduce the behavior:
- Serialize a CloudEvent with Jackson
Code Snippet
package org.example.functions;
import com.azure.core.models.CloudEvent;
import com.azure.core.models.CloudEventDataFormat;
import com.azure.core.util.BinaryData;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Jackson {
private static class Foo {
private final String bar;
public Foo(String bar) {
this.bar = bar;
}
public String getBar() {
return bar;
}
}
public static void main(String[] args) throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
BinaryData binaryData = BinaryData.fromObject(new Foo("bar"));
CloudEvent cloudEvent = new CloudEvent("mySource", "myType", binaryData, CloudEventDataFormat.JSON, "application/json");
System.out.println(objectMapper.writeValueAsString(cloudEvent));
}
}Expected behavior
The data object contains a correct representation:
{"id":"c4c53894-46ab-40ff-abe7-9fe2bc8c215e","source":"mySource","data":{"bar":"bar"},"data_base64":null,"type":"myType","time":null,"specversion":"1.0","dataschema":null,"datacontenttype":"application/json","subject":null}instead of
{"id":"c4c53894-46ab-40ff-abe7-9fe2bc8c215e","source":"mySource","data":{"replayable":true,"length":13},"data_base64":null,"type":"myType","time":null,"specversion":"1.0","dataschema":null,"datacontenttype":"application/json","subject":null}Setup (please complete the following information):
- OS: MacOs
- IDE: IntelliJ
- Library/Libraries: com.azure:azure-core:1.41.0
- Java version: 8
- App Server/Environment: N.A.
- Frameworks: N.A
Additional context
- Related issue in function worker: OutputBinding not compatible with com.azure.core.models.CloudEvent azure-functions-java-worker#720
- There is a @JsonIgnore annotation on com.azure.core.models.CloudEvent#binaryData
- There is a @JsonProperty annotation on com.azure.core.models.CloudEvent#data
- The getData implementation returns BinaryData instead of JsonNode
- Jackson serializes the data attribute through the getter method (getData) resulting in a mismatch and a loss of content.
@JsonProperty("data")
private JsonNode data;
@JsonProperty("data_base64")
private String dataBase64;
@JsonIgnore
private BinaryData binaryData;
public BinaryData getData() {
if (this.binaryData == null) {
if (this.data != null) {
this.binaryData = BinaryData.fromObject(this.data, SERIALIZER);
} else if (this.dataBase64 != null) {
this.binaryData = BinaryData.fromBytes(Base64.getDecoder().decode(this.dataBase64));
}
}
return this.binaryData;
}Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Bug Description Added
- Repro Steps Added
- Setup information Added
Metadata
Metadata
Assignees
Labels
ClientThis issue points to a problem in the data-plane of the library.This issue points to a problem in the data-plane of the library.Event Gridcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.Issues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as thatThe issue doesn't require a change to the product in order to be resolved. Most issues start as that