Skip to content

Commit f75050a

Browse files
committed
Add canonize(Map<String, Object>,) methods
1 parent 254763d commit f75050a

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.apicatalog</groupId>
77
<artifactId>titanium-jcs</artifactId>
8-
<version>3.0.0-M2</version>
8+
<version>3.0.0-M3</version>
99
<packaging>jar</packaging>
1010

1111
<url>https://github.com/filip26/titanium-jcs</url>

src/main/java/com/apicatalog/jcs/Jcs.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
import java.text.DecimalFormat;
2323
import java.text.DecimalFormatSymbols;
2424
import java.util.Locale;
25+
import java.util.Map;
2526

2627
import com.apicatalog.tree.io.Tree.NodeType;
2728
import com.apicatalog.tree.io.TreeAdapter;
2829
import com.apicatalog.tree.io.TreeComparison;
2930
import com.apicatalog.tree.io.TreeIOException;
31+
import com.apicatalog.tree.io.java.JavaAdapter;
3032

3133
/**
3234
* An implementation of the <a href="https://www.rfc-editor.org/rfc/rfc8785">RFC
@@ -76,6 +78,19 @@ public final class Jcs {
7678
private static final DecimalFormat PLAIN_FORMAT = new DecimalFormat("0.#####################",
7779
new DecimalFormatSymbols(Locale.ENGLISH));
7880

81+
/**
82+
* Canonicalizes as JSON object according to JCS (RFC 8785) and returns the
83+
* result as a {@link String}.
84+
*
85+
* @param value the Map representing JSON object to canonicalize (can be
86+
* {@code null})
87+
* @return a string containing the canonical JSON representation
88+
* @throws TreeIOException
89+
*/
90+
public static String canonize(final Map<String, Object> value) throws TreeIOException {
91+
return canonize(value, JavaAdapter.instance());
92+
}
93+
7994
/**
8095
* Canonicalizes a JSON value according to JCS (RFC 8785) and returns the result
8196
* as a {@link String}.
@@ -97,6 +112,21 @@ public static String canonize(final Object value, final TreeAdapter adapter) thr
97112
}
98113
}
99114

115+
/**
116+
* Canonicalizes as JSON object according to JCS (RFC 8785) and writes the
117+
* output to the provided {@link Writer}.
118+
*
119+
* @param value the Map representing JSON object to canonicalize (can be
120+
* {@code null})
121+
* @param writer the {@link Writer} to which the canonical output is written
122+
* @throws IOException if an I/O error occurs
123+
* @throws TreeIOException
124+
*/
125+
public static void canonize(final Map<String, Object> value, final Writer writer)
126+
throws IOException, TreeIOException {
127+
canonize(value, JavaAdapter.instance(), writer);
128+
}
129+
100130
/**
101131
* Canonicalizes a JSON value according to JCS (RFC 8785) and writes the output
102132
* to the provided {@link Writer}.

0 commit comments

Comments
 (0)