JSON serialization - extensions of types OffsetDateTime and bytes[] deserialized as Strings
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
Bắt đầu với bản tái hiện JsonSerializationTest và các điểm vào CloudEventJsonSerializer và CloudEventJsonDeserializer được hiển thị trong issue. Chạy bài kiểm thử với các phần mở rộng OffsetDateTime và bytes[] được bật, sau đó theo dõi quá trình xử lý định dạng JSON của EventFormatProvider. Công việc được xem là hoàn tất khi các giá trị phần mở rộng đó giữ nguyên kiểu ban đầu và các assertions đạt sau khi tuần tự hóa round-trip.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Extensions of types OffsetDateTime and bytes[] are not restored properly after serialization and deserialization using JSON format. Values are Strings.
class JsonSerializationTest {
final CloudEventJsonSerializer serializer = new CloudEventJsonSerializer();
final CloudEventJsonDeserializer deserializer = new CloudEventJsonDeserializer();
@Test
void shouldSerializeAndDeserialize() {
CloudEvent serialized = createTestEvent();
Buffer buffer = serializer.serialize(serialized);
CloudEvent deserialized = deserializer.deserialize(buffer);
assertEvent(serialized, deserialized);
}
private CloudEvent createTestEvent() {
return CloudEventBuilder.v1()
.withId("id")
.withSource(URI.create("source"))
.withType("type")
.withDataContentType("datacontenttype")
.withDataSchema(URI.create("https://data/schema"))
.withSubject("subject")
.withTime(OffsetDateTime.now(ZoneId.of("UTC")))
.withExtension("extstring", "extstring-value")
.withExtension("extboolean", true)
.withExtension("extint", 123)
// Not working, deserialized value is string
// .withExtension("exttime", OffsetDateTime.now(ZoneId.of("UTC")))
// Not working, deserialized value is string
// .withExtension("extbytes", "bytes".getBytes(StandardCharsets.UTF_8))
.withData("test data".getBytes(StandardCharsets.UTF_8))
.build();
}
private void assertEvent(CloudEvent expected, CloudEvent actual) {
assertNotNull(actual);
assertEquals(expected.getId(), actual.getId());
assertEquals(expected.getSource(), actual.getSource());
assertEquals(expected.getSpecVersion(), actual.getSpecVersion());
assertEquals(expected.getType(), actual.getType());
assertEquals(expected.getDataContentType(), actual.getDataContentType());
assertEquals(expected.getDataSchema(), actual.getDataSchema());
assertEquals(expected.getSubject(), actual.getSubject());
assertEquals(expected.getTime(), actual.getTime());
assertEquals(expected.getData(), actual.getData());
assertEquals(expected.getExtensionNames(), actual.getExtensionNames());
expected.getExtensionNames().forEach(extName -> {
if (expected.getExtension(extName) instanceof byte[]) {
assertInstanceOf(byte[].class, actual.getExtension(extName),
"Extension " + extName + " is not a byte[]");
assertArrayEquals((byte[]) expected.getExtension(extName),
(byte[]) actual.getExtension(extName),
"Values not equal for extension " + extName);
} else {
assertEquals(expected.getExtension(extName), actual.getExtension(extName),
"Values not equal for extension " + extName);
}
}
);
}
}
public class CloudEventJsonSerializer implements Serializer<CloudEvent> {
@Override
public boolean handles(Object payload) {
return payload instanceof CloudEvent;
}
@Override
public Buffer serialize(CloudEvent payload) {
byte[] serialized = Objects.requireNonNull(
EventFormatProvider
.getInstance()
.resolveFormat(ContentType.JSON),
"JSON event format dependency missing")
.serialize(payload);
return Buffer.buffer(serialized);
}
}
public class CloudEventJsonDeserializer implements Deserializer<CloudEvent> {
@Override
public CloudEvent deserialize(Buffer payload) {
return Objects.requireNonNull(
EventFormatProvider
.getInstance()
.resolveFormat(ContentType.JSON),
"JSON event format dependency missing")
.deserialize(payload.getBytes());
}
}
- Ngôn ngữ chính
- Java
- Star
- 446
- Fork
- 172
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của cloudevents/sdk-java
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
cloudevents/sdk-java#731 · 1 reaction ·
-
bug
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
cloudevents/sdk-java#697 · 3 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
cloudevents/sdk-java#689 · 2 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
cloudevents/sdk-java#660 · 2 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
cloudevents/sdk-java#711 · 1 bình luận ·
Tất cả issue của cloudevents/sdk-java
Issue tương tự
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
apache/cloudstack#14222 ·
-
[BUG]茶杯方块在取茶时会引发崩溃 Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Cannot differ own consent and managed consents in My Consents view and detailed consent view. Đang mở1.0.0-alpha2 Type/Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
wso2/dpdp-accelerator#272 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
infinispan/infinispan#18150 ·
-
area/frontend
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100