This repository was archived by the owner on Dec 19, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +32
-6
lines changed
playground-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/playground/boot Expand file tree Collapse file tree 2 files changed +32
-6
lines changed Original file line number Diff line number Diff line change 11package com .oembedler .moon .playground .boot ;
22
3+ import com .fasterxml .jackson .databind .annotation .JsonSerialize ;
34import lombok .Data ;
5+ import org .springframework .core .io .Resource ;
46
57import java .util .List ;
68import java .util .Map ;
@@ -14,24 +16,27 @@ public class PlaygroundTab {
1416 private String endpoint ;
1517
1618 /**
17- * The GraphQL query (operation) to be initially displayed on the tab.
19+ * The GraphQL query (operation) to be initially displayed on the tab. It should be a graphql resource.
1820 */
19- private String query ;
21+ @ JsonSerialize (using = ResourceSerializer .class )
22+ private Resource query ;
2023
2124 /**
2225 * The name of the tab.
2326 */
2427 private String name ;
2528
2629 /**
27- * The query variables. It should be a serialized JSON.
30+ * The query variables. It should be a JSON resource .
2831 */
29- private String variables ;
32+ @ JsonSerialize (using = ResourceSerializer .class )
33+ private Resource variables ;
3034
3135 /**
32- * The list of responses to be displayed under "responses". Should be a list of serialized JSONs .
36+ * The list of responses to be displayed under "responses". It should be a list of JSON resources .
3337 */
34- private List <String > responses ;
38+ @ JsonSerialize (contentUsing = ResourceSerializer .class )
39+ private List <Resource > responses ;
3540
3641 /**
3742 * HTTP headers. Key-value pairs expected.
Original file line number Diff line number Diff line change 1+ package com .oembedler .moon .playground .boot ;
2+
3+ import com .fasterxml .jackson .core .JsonGenerator ;
4+ import com .fasterxml .jackson .databind .JsonSerializer ;
5+ import com .fasterxml .jackson .databind .SerializerProvider ;
6+ import org .apache .tomcat .util .http .fileupload .util .Streams ;
7+ import org .springframework .boot .jackson .JsonComponent ;
8+ import org .springframework .core .io .Resource ;
9+
10+ import java .io .IOException ;
11+ import java .nio .charset .StandardCharsets ;
12+
13+ @ JsonComponent
14+ public class ResourceSerializer extends JsonSerializer <Resource > {
15+ @ Override
16+ public void serialize (final Resource value , final JsonGenerator gen , final SerializerProvider serializers )
17+ throws IOException {
18+ final String content = Streams .asString (value .getInputStream (), StandardCharsets .UTF_8 .name ());
19+ gen .writeString (content );
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments