|
| 1 | +/* |
| 2 | + * Copyright 2020-Present The Serverless Workflow Specification Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package io.serverlessworkflow.api.deserializers; |
| 17 | + |
| 18 | +import com.fasterxml.jackson.core.JsonParser; |
| 19 | +import com.fasterxml.jackson.databind.DeserializationContext; |
| 20 | +import com.fasterxml.jackson.databind.JsonNode; |
| 21 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 22 | +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; |
| 23 | +import io.serverlessworkflow.api.end.ContinueAs; |
| 24 | +import io.serverlessworkflow.api.interfaces.WorkflowPropertySource; |
| 25 | +import io.serverlessworkflow.api.timeouts.WorkflowExecTimeout; |
| 26 | + |
| 27 | +import java.io.IOException; |
| 28 | + |
| 29 | +public class ContinueAsDeserializer extends StdDeserializer<ContinueAs> { |
| 30 | + |
| 31 | + private static final long serialVersionUID = 510l; |
| 32 | + |
| 33 | + @SuppressWarnings("unused") |
| 34 | + private WorkflowPropertySource context; |
| 35 | + |
| 36 | + public ContinueAsDeserializer() { |
| 37 | + this(ContinueAs.class); |
| 38 | + } |
| 39 | + |
| 40 | + public ContinueAsDeserializer(Class<?> vc) { |
| 41 | + super(vc); |
| 42 | + } |
| 43 | + |
| 44 | + public ContinueAsDeserializer(WorkflowPropertySource context) { |
| 45 | + this(ContinueAs.class); |
| 46 | + this.context = context; |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public ContinueAs deserialize(JsonParser jp, |
| 51 | + DeserializationContext ctxt) throws IOException { |
| 52 | + |
| 53 | + ObjectMapper mapper = (ObjectMapper) jp.getCodec(); |
| 54 | + JsonNode node = jp.getCodec().readTree(jp); |
| 55 | + |
| 56 | + ContinueAs continueAs = new ContinueAs(); |
| 57 | + |
| 58 | + if (!node.isObject()) { |
| 59 | + continueAs.setWorkflowId(node.asText()); |
| 60 | + continueAs.setVersion(null); |
| 61 | + continueAs.setData(null); |
| 62 | + continueAs.setWorkflowExecTimeout(null); |
| 63 | + return continueAs; |
| 64 | + } else { |
| 65 | + if (node.get("workflowId") != null) { |
| 66 | + continueAs.setWorkflowId(node.get("workflowId").asText()); |
| 67 | + } |
| 68 | + |
| 69 | + if (node.get("version") != null) { |
| 70 | + continueAs.setVersion(node.get("version").asText()); |
| 71 | + } |
| 72 | + |
| 73 | + if (node.get("data") != null) { |
| 74 | + continueAs.setData(node.get("data").asText()); |
| 75 | + } |
| 76 | + |
| 77 | + if (node.get("workflowExecTimeout") != null) { |
| 78 | + continueAs.setWorkflowExecTimeout(mapper.treeToValue(node.get("workflowExecTimeout"), WorkflowExecTimeout.class)); |
| 79 | + } |
| 80 | + |
| 81 | + return continueAs; |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | + |
0 commit comments