Merge pull request #7990 from Johannes Edmeier
* gh-7990: Polish "Avoid property name collisions when serializing AuditEvent to JSON" Avoid property name collisions when serializing AuditEvent to JSON
This commit is contained in:
commit
6d22e5b733
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2016 the original author or authors.
|
* Copyright 2012-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -22,7 +22,6 @@ import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAnyGetter;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||||
|
|
@ -137,7 +136,6 @@ public class AuditEvent implements Serializable {
|
||||||
* Returns the event data.
|
* Returns the event data.
|
||||||
* @return the event data
|
* @return the event data
|
||||||
*/
|
*/
|
||||||
@JsonAnyGetter
|
|
||||||
public Map<String, Object> getData() {
|
public Map<String, Object> getData() {
|
||||||
return this.data;
|
return this.data;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2016 the original author or authors.
|
* Copyright 2012-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -18,10 +18,13 @@ package org.springframework.boot.actuate.audit;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -74,4 +77,17 @@ public class AuditEventTests {
|
||||||
new AuditEvent("phil", null, Collections.singletonMap("a", (Object) "b"));
|
new AuditEvent("phil", null, Collections.singletonMap("a", (Object) "b"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void jsonFormat() throws Exception {
|
||||||
|
AuditEvent event = new AuditEvent("johannes", "UNKNOWN",
|
||||||
|
Collections.singletonMap("type", (Object) "BadCredentials"));
|
||||||
|
String json = Jackson2ObjectMapperBuilder.json().build()
|
||||||
|
.writeValueAsString(event);
|
||||||
|
System.out.println(json);
|
||||||
|
JSONObject jsonObject = new JSONObject(json);
|
||||||
|
assertThat(jsonObject.getString("type")).isEqualTo("UNKNOWN");
|
||||||
|
assertThat(jsonObject.getJSONObject("data").getString("type"))
|
||||||
|
.isEqualTo("BadCredentials");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue