Skip to content

Commit

Permalink
fixed serialization/deserialization of LogEntry
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Aug 2, 2022
1 parent 15f6be0 commit 939fd55
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public static LogEntry fromJson(final JsonObject jsonObject) {
final String message = jsonObject.getValueOrThrow(JsonFields.MESSAGE);
final String address = jsonObject.getValue(JsonFields.ADDRESS).orElse(null);
final EntityId entityId = jsonObject.getValue(JsonFields.ENTITY_ID)
.map(eId -> EntityId.of(EntityType.of("unknown"), eId))
.map(eId -> EntityId.of(
EntityType.of(jsonObject.getValue(JsonFields.ENTITY_TYPE).orElse("unknown")), eId))
.orElse(null);

return getBuilder(correlationId, timestamp, category, type, level, message, address, entityId)
Expand Down Expand Up @@ -178,6 +179,7 @@ public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<
builder.set(JsonFields.ADDRESS, address);
}
if (null != entityId) {
builder.set(JsonFields.ENTITY_TYPE, entityId.getEntityType().toString());
builder.set(JsonFields.ENTITY_ID, entityId.toString());
}
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ final class JsonFields {
JsonFactory.newStringFieldDefinition("address", FieldType.REGULAR,
JsonSchemaVersion.V_2);

/**
* JSON field containing the entity type.
* @since 3.0.0
*/
public static final JsonFieldDefinition<String> ENTITY_TYPE =
JsonFactory.newStringFieldDefinition("entityType", FieldType.REGULAR,
JsonSchemaVersion.V_2);


/**
* JSON field containing the entity ID.
* @since 2.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ private static JsonObject getLogEntryJson() {
.set(LogEntry.JsonFields.LEVEL, LEVEL.getLevel())
.set(LogEntry.JsonFields.ADDRESS, ADDRESS)
.set(LogEntry.JsonFields.ENTITY_ID, THING_ID.toString())
.set(LogEntry.JsonFields.ENTITY_TYPE, THING_ID.getEntityType().toString())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public static final class Json {
.set(LogEntry.JsonFields.LEVEL, LEVEL.getLevel())
.set(LogEntry.JsonFields.ADDRESS, ADDRESS)
.set(LogEntry.JsonFields.ENTITY_ID, THING_ID.toString())
.set(LogEntry.JsonFields.ENTITY_TYPE, THING_ID.getEntityType().toString())
.build();
public static final JsonObject ENTRY_2_JSON = JsonFactory.newObjectBuilder()
.set(LogEntry.JsonFields.CORRELATION_ID, CORRELATION_ID)
Expand All @@ -270,6 +271,7 @@ public static final class Json {
.set(LogEntry.JsonFields.LEVEL, LEVEL.getLevel())
.set(LogEntry.JsonFields.ADDRESS, ADDRESS)
.set(LogEntry.JsonFields.ENTITY_ID, THING_ID.toString())
.set(LogEntry.JsonFields.ENTITY_TYPE, THING_ID.getEntityType().toString())
.build();

public static final JsonArray ENTRIES_JSON = JsonFactory.newArrayBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class FluentPublishingConnectionLogger
private static final String TAG_TYPE = toTag(LogEntry.JsonFields.TYPE);
private static final String TAG_CORRELATION_ID = toTag(LogEntry.JsonFields.CORRELATION_ID);
private static final String TAG_ADDRESS = toTag(LogEntry.JsonFields.ADDRESS);
private static final String TAG_ENTITY_TYPE = "entityType";
private static final String TAG_ENTITY_TYPE = toTag(LogEntry.JsonFields.ENTITY_TYPE);
private static final String TAG_ENTITY_ID = toTag(LogEntry.JsonFields.ENTITY_ID);
private static final String TAG_MESSAGE = toTag(LogEntry.JsonFields.MESSAGE);
private static final String TAG_INSTANCE_ID = "instanceId";
Expand Down

0 comments on commit 939fd55

Please sign in to comment.