Skip to content

Commit a1311f6

Browse files
committed
fix: add JSON serializationformatting
Signed-off-by: “Kevin” <kevlar_ksb@yahoo.com>
1 parent 7e9deee commit a1311f6

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/main/java/com/uber/cadence/samples/query/MarkdownFormattedResponse.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package com.uber.cadence.samples.query;
1919

20+
import com.fasterxml.jackson.annotation.JsonCreator;
21+
import com.fasterxml.jackson.annotation.JsonProperty;
22+
2023
/**
2124
* The JSON shape Cadence Web (v4.0.14+) expects for formatted query responses. When a {@link
2225
* com.uber.cadence.workflow.QueryMethod} returns this object, the default data converter serializes
@@ -39,15 +42,28 @@ public final class MarkdownFormattedResponse {
3942
private final String format;
4043
private final String data;
4144

45+
/**
46+
* Constructor for JSON deserialization (e.g. Java clients using the Cadence SDK data converter).
47+
* A no-arg constructor cannot populate {@code private final} fields; {@code @JsonCreator} with
48+
* explicit properties is required.
49+
*/
50+
@JsonCreator
51+
private MarkdownFormattedResponse(
52+
@JsonProperty("cadenceResponseType") String cadenceResponseType,
53+
@JsonProperty("format") String format,
54+
@JsonProperty("data") String data) {
55+
this.cadenceResponseType = cadenceResponseType;
56+
this.format = format;
57+
this.data = data;
58+
}
59+
4260
/**
4361
* @param markdownData the markdown string to render in Cadence Web. May include Markdoc tags such
4462
* as {@code {%- signal -%}} and {@code {%- start -%}}.
4563
*/
4664
public MarkdownFormattedResponse(String markdownData) {
4765
// These two values are the required constants that Cadence Web checks for.
48-
this.cadenceResponseType = "formattedData";
49-
this.format = "text/markdown";
50-
this.data = markdownData;
66+
this("formattedData", "text/markdown", markdownData);
5167
}
5268

5369
public String getCadenceResponseType() {

0 commit comments

Comments
 (0)