@@ -52,37 +52,35 @@ public C2paToolInvoker(String c2paToolPath) {
5252
5353
5454
55- /**
55+ /**
5656 * Backwards-compatible wrapper used by existing code/tests.
57- *
5857 * Historically, the service used a plain JSON string "manifest" coming
5958 * from c2patool. We now normalize that into {@link C2paMetadata}, but
6059 * expose this helper for callers that still expect a String.
61- *
6260 * Contract:
6361 * - Never throws.
6462 * - Returns a JSON serialization of {@link C2paMetadata}.
6563 */
66- @ Deprecated
67- public String extractManifest (File imageFile ) {
68- C2paMetadata metadata = extractMetadata (imageFile );
64+ @ Deprecated
65+ public String extractManifest (File imageFile ) {
66+ C2paMetadata metadata = extractMetadata (imageFile );
67+ try {
68+ ObjectMapper mapper = new ObjectMapper ();
69+ return mapper .writeValueAsString (metadata );
70+ } catch (Exception e ) {
71+ String msg = "Failed to serialize C2PA metadata to JSON: " + e ;
72+ log .warn (msg , e );
73+ C2paMetadata error = C2paMetadata .error (msg );
6974 try {
7075 ObjectMapper mapper = new ObjectMapper ();
71- return mapper .writeValueAsString (metadata );
72- } catch (Exception e ) {
73- String msg = "Failed to serialize C2PA metadata to JSON: " + e ;
74- log .warn (msg , e );
75- C2paMetadata error = C2paMetadata .error (msg );
76- try {
77- ObjectMapper mapper = new ObjectMapper ();
78- return mapper .writeValueAsString (error );
79- } catch (Exception inner ) {
80- log .warn ("Secondary failure serializing error C2PA metadata: {}" , inner .toString ());
81- // Last-resort JSON so callers never get null
82- return "{\" c2paErrorFlag\" :1,\" c2paErrorMessage\" :\" serialization failure\" }" ;
83- }
76+ return mapper .writeValueAsString (error );
77+ } catch (Exception inner ) {
78+ log .warn ("Secondary failure serializing error C2PA metadata: {}" , inner .toString ());
79+ // Last-resort JSON so callers never get null
80+ return "{\" c2paErrorFlag\" :1,\" c2paErrorMessage\" :\" serialization failure\" }" ;
8481 }
8582 }
83+ }
8684
8785 /**
8886 * Executes the C2PA tool and converts its output into ML-ready metadata.
@@ -192,7 +190,7 @@ private C2paMetadata parseMetadataFromJson(String json) {
192190 // Resolve active manifest (preferred) or fall back to first manifest.
193191 JsonNode activeManifestField = root .get ("active_manifest" );
194192 String activeManifestId =
195- ( activeManifestField != null && !activeManifestField .isNull () )
193+ activeManifestField != null && !activeManifestField .isNull ()
196194 ? activeManifestField .asText (null )
197195 : null ;
198196
0 commit comments