Commit 3e88c366 authored by Andy Wilkinson's avatar Andy Wilkinson

Polish "Avoid property name collisions when serializing AuditEvent to JSON"

See gh-7990
parent fcf36ed0
/* /*
* 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.
......
/* /*
* 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.
...@@ -79,12 +79,15 @@ public class AuditEventTests { ...@@ -79,12 +79,15 @@ public class AuditEventTests {
@Test @Test
public void jsonFormat() throws Exception { public void jsonFormat() throws Exception {
AuditEvent event = new AuditEvent("johannes", "UNKNOWN", Collections.singletonMap("type", (Object) "BadCredentials")); AuditEvent event = new AuditEvent("johannes", "UNKNOWN",
Collections.singletonMap("type", (Object) "BadCredentials"));
String json = Jackson2ObjectMapperBuilder.json().build().writeValueAsString(event); String json = Jackson2ObjectMapperBuilder.json().build()
.writeValueAsString(event);
System.out.println(json);
JSONObject jsonObject = new JSONObject(json); JSONObject jsonObject = new JSONObject(json);
assertThat(jsonObject.getString("type")).isEqualTo("UNKNOWN"); assertThat(jsonObject.getString("type")).isEqualTo("UNKNOWN");
assertThat(jsonObject.getJSONObject("data").getString("type"))
.isEqualTo("BadCredentials");
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment