|
3 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; |
4 | 4 | import com.fasterxml.jackson.databind.ObjectMapper; |
5 | 5 | import foundation.identity.did.representations.Representations; |
6 | | -import foundation.identity.did.representations.consumption.RepresentationConsumerDID; |
7 | 6 | import foundation.identity.did.representations.production.RepresentationProducerDID; |
8 | 7 | import foundation.identity.did.representations.production.RepresentationProducerDIDCBOR; |
9 | 8 | import foundation.identity.did.representations.production.RepresentationProducerDIDJSON; |
@@ -85,9 +84,9 @@ public static String httpBodyForResult(Result result) throws IOException { |
85 | 84 | byte[] content = result.getFunctionContent(); |
86 | 85 | if (content == null || content.length == 0) { |
87 | 86 | json.put(functionContentProperty, null); |
88 | | - } else if (isContentTypeJson(result)) { |
| 87 | + } else if (isContentJson(result)) { |
89 | 88 | json.put(functionContentProperty, objectMapper.readValue(new ByteArrayInputStream(content), LinkedHashMap.class)); |
90 | | - } else if (isContentTypeText(result)) { |
| 89 | + } else if (isContentText(result)) { |
91 | 90 | json.put(functionContentProperty, new String(content, StandardCharsets.UTF_8)); |
92 | 91 | } else { |
93 | 92 | json.put(functionContentProperty, Base64.getEncoder().encodeToString(content)); |
@@ -142,11 +141,13 @@ public static String dereferenceAcceptForHttpAccepts(List<MediaType> httpAcceptM |
142 | 141 | * Helper methods |
143 | 142 | */ |
144 | 143 |
|
145 | | - private static boolean isContentTypeJson(Result result) { |
146 | | - return RepresentationProducerDID.MEDIA_TYPE.equals(result.getContentType()) || result.getContentType().contains("+json") || result.getContentType().contains("/json"); |
| 144 | + private static boolean isContentJson(Result result) throws IOException { |
| 145 | + boolean isContentTypeJson = RepresentationProducerDID.MEDIA_TYPE.equals(result.getContentType()) || result.getContentType().contains("+json") || result.getContentType().contains("/json"); |
| 146 | + boolean isContentJson = result.getFunctionContent()[0] == '{' || result.getFunctionContent()[0] == '['; |
| 147 | + return isContentTypeJson && isContentJson; |
147 | 148 | } |
148 | 149 |
|
149 | | - private static boolean isContentTypeText(Result result) { |
| 150 | + private static boolean isContentText(Result result) { |
150 | 151 | return result.getContentType().startsWith("text/"); |
151 | 152 | } |
152 | 153 | } |
0 commit comments