summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JSONUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JSONUtil.java')
-rw-r--r--sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JSONUtil.java43
1 files changed, 32 insertions, 11 deletions
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JSONUtil.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JSONUtil.java
index e21a2402b1..492dfae3dd 100644
--- a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JSONUtil.java
+++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JSONUtil.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.tuscany.sca.binding.websocket.runtime;
import java.util.ArrayList;
@@ -111,17 +129,20 @@ public class JSONUtil {
return builder.toString();
}
- /**
- * Decode JSON to a given Java type.
- *
- * @param responseJSON
- * the json to convert
- * @param returnType
- * the return type to convert to
- * @return the converted object
- */
- public static Object decodeResponse(String responseJSON, Class<?> returnType) {
- return gson.fromJson(responseJSON, returnType);
+ public static String encodeRequest(WebSocketBindingRequest request) {
+ return gson.toJson(request);
+ }
+
+ public static WebSocketBindingRequest decodeRequest(String jsonRequest) {
+ return gson.fromJson(jsonRequest, WebSocketBindingRequest.class);
+ }
+
+ public static WebSocketBindingResponse decodeResponse(String operationResponse) {
+ return gson.fromJson(operationResponse, WebSocketBindingResponse.class);
+ }
+
+ public static Object decodeResponsePayload(String payload, Class<?> returnType) {
+ return gson.fromJson(payload, returnType);
}
}