Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid missing escaping of reserved characters #278

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package <%=packageName%>.web.rest.dto;

import org.javers.core.metamodel.object.CdoSnapshot;
import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.Instant;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.javers.core.metamodel.object.CdoSnapshot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class EntityAuditEvent implements Serializable {

public class EntityAuditEvent implements Serializable{
private static final Logger LOG = LoggerFactory.getLogger(EntityAuditEvent.class);

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -144,20 +153,14 @@ public class EntityAuditEvent implements Serializable{
entityAuditEvent.setModifiedBy(snapshot.getCommitMetadata().getAuthor());

if (snapshot.getState().getPropertyNames().size() > 0) {
int count = 0;
StringBuilder sb = new StringBuilder("{");

for (String s:snapshot.getState().getPropertyNames()) {
count++;
Object propertyValue = snapshot.getPropertyValue(s);
sb.append("\"" + s + "\": \"" + propertyValue + "\"");
if (count < snapshot.getState().getPropertyNames().size()) {
sb.append(",");
}
}

sb.append("}");
entityAuditEvent.setEntityValue(sb.toString());
final Map<String, Object> map = new HashMap<>();
snapshot.getState().mapProperties((key, value) -> map.put(key, value != null ? value.toString() : null));

try {
entityAuditEvent.setEntityValue(new ObjectMapper().writeValueAsString(map));
} catch (JsonProcessingException e) {
LOG.error("Error while producing entityValue JSON string", e);
}
}
LocalDateTime localTime = snapshot.getCommitMetadata().getCommitDate();

Expand Down
Loading