ClaimBuilder also returns a Map representation

pull/17/merge
Richard Körber 2015-12-24 16:12:35 +01:00
parent 7f69a14e2a
commit f87dba266f
2 changed files with 15 additions and 0 deletions

View File

@ -15,6 +15,7 @@ package org.shredzone.acme4j.util;
import java.security.Key;
import java.security.PublicKey;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
@ -157,6 +158,13 @@ public class ClaimBuilder {
return this;
}
/**
* Returns a {@link Map} representation of the claims.
*/
public Map<String, Object> toMap() {
return Collections.unmodifiableMap(data);
}
/**
* Returns a JSON representation of the claims.
*/

View File

@ -62,6 +62,13 @@ public class ClaimBuilderTest {
assertThat(res, is(sameInstance(cb)));
assertThat(cb.toString(), is("{\"fooInt\":456,\"fooStr\":\"String\"}"));
Map<String, Object> map = cb.toMap();
assertThat(map.keySet(), hasSize(2));
assertThat(map, allOf(
hasEntry("fooInt", (Object) 456),
hasEntry("fooStr", (Object) "String")
));
}
/**