Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions core/src/main/java/io/cloudevents/core/impl/BaseCloudEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,14 @@ public <T extends CloudEventWriter<V>, V> V read(CloudEventWriterFactory<T, V> w
}

protected void readExtensions(CloudEventContextWriter writer) throws CloudEventRWException {
// TODO to be improved
for (Map.Entry<String, Object> entry : this.extensions.entrySet()) {
if (entry.getValue() instanceof String) {
writer.withContextAttribute(entry.getKey(), (String) entry.getValue());
} else if (entry.getValue() instanceof Number) {
writer.withContextAttribute(entry.getKey(), (Number) entry.getValue());
} else if (entry.getValue() instanceof Boolean) {
writer.withContextAttribute(entry.getKey(), (Boolean) entry.getValue());
} else if (entry.getValue() instanceof URI) {
writer.withContextAttribute(entry.getKey(), (URI) entry.getValue());
} else if (entry.getValue() instanceof OffsetDateTime) {
writer.withContextAttribute(entry.getKey(), (OffsetDateTime) entry.getValue());
} else if (entry.getValue() instanceof byte[]) {
writer.withContextAttribute(entry.getKey(), (byte[]) entry.getValue());
Object value = entry.getValue();
if (value instanceof String || value instanceof Number || value instanceof Boolean || value instanceof URI) {
writer.withContextAttribute(entry.getKey(), value.toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the .toString() is not equivalent to previous implementation that was using typed methods.

The original issue is not clear what the optimization is?

} else if (value instanceof OffsetDateTime) {
writer.withContextAttribute(entry.getKey(), (OffsetDateTime) value);
} else if (value instanceof byte[]) {
writer.withContextAttribute(entry.getKey(), (byte[]) value);
} else {
// This should never happen because we build that map only through our builders
throw new IllegalStateException("Illegal value inside extensions map: " + entry);
Expand Down