2222import java .text .DecimalFormat ;
2323import java .text .DecimalFormatSymbols ;
2424import java .util .Locale ;
25+ import java .util .Map ;
2526
2627import com .apicatalog .tree .io .Tree .NodeType ;
2728import com .apicatalog .tree .io .TreeAdapter ;
2829import com .apicatalog .tree .io .TreeComparison ;
2930import 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